JavaScript is the original and common name applied towards most flavors of a scripting language that originated on NetScape Navigator. Use this tag for questions regarding common implementations of ECMAScript, JavaScript, JScript, etc. JS does not typically refer to its ECMA-cousin, ActionScript.

learn more… | top users | synonyms (1)

2
votes
1answer
146 views

Javascript Closure Style Similar to Java Class Structure

PROBLEM: There is a coding imperative (S. McConnel, Code Complete) that one shouldn't code on language, but by means of it, e.g. doing right style things even if language doesn't have some ...
3
votes
1answer
95 views

How to handle a client app that connects to a TCP server and sends/receives text data bidirectionally?

I've got a conceptual question (which is probably better posted here than on StackOverflow?). I want to develop a client application that maintains a persistent connection to a server, and exchanges ...
0
votes
1answer
130 views

Handling multiple asynchronous events - Wait for pending offers to process on new offer?

I have a programming problem, that I don't know how to solve. And while I have provided a sample of my code, I am interested in a conceptual answer on how to resolve this problem. On a tradeOffers ...
4
votes
1answer
143 views

Filtering request and responses in RESTful MEAN stack

I have a very basic RESTful service written using the MEAN stack (MongoDb, Express.js, Angular.js, Node.js) and utilizing the Mongoose ODM. Product schema var productSchema = new mongoose.Schema({ ...
3
votes
1answer
54 views

Should I be returning promises from any function that uses them?

Promises is a fairly new pattern for me, so I'm still building my intuition for them. I recently came across a case where some code in an adapter-like bit of code was once synchronous, and then ...
-3
votes
1answer
168 views

different between ES6 and Javascript [closed]

What is ES6? Is it JavaScript? Or multiple language supporter? I searched for it but can't understand it, especially the page on Wikipedia. Is it better than Javascript? And what can I do in my web ...
3
votes
1answer
97 views

Javascript Promise chaining [closed]

I recently started working with JS Promises. What I always like to do, is create function, which returns a Promise with the final desired result, but I only do 1 operation/then. Consider something ...
0
votes
0answers
76 views

AngularJS and NodeJS required version

I am new to the world of Javascript and their frameworks, and I feel a bit lost with this. I am trying to follow the official toutorial of AngularJS. In one of the first sections, it reads Install ...
-5
votes
2answers
126 views

Technology like SignalR but client side [closed]

I would like to program a software that will heavily utilize client side development (JavaScript), and I want to communicate with the server. Is there a way similar to SignalR where I can keep ...
5
votes
1answer
390 views

Why doesn't ES6 have thin-arrow functions?

ES6 added fat-arrow functions (=>), which have two major differences from normal functions: shorter syntax (including implicit return if you use a single-expression body) inherit this from ...
4
votes
2answers
264 views

Methods of separating front and back-end with full stack javascript?

Suppose I have a front-end which is mostly a single-page application written using angular, grunt, and bower. And suppose I have a backend, which is mostly just a REST API sitting on top of an ORM, ...
-2
votes
1answer
68 views

Is it better to have a single, more general directive or multiple type based directives in Angular?

Is it considered good practice to have: Single, general directive that has multiple data-* parameters and serial data is binded from controller Single, general directive that has config and serial ...
10
votes
3answers
278 views

How do you use duck typing in javascript without always checking for properties and methods?

I know javascript uses duck typing and at first I thought this would make polymorphism easy compared to strongly typed languages like C#. But now my functions that take arguments are littered with ...
2
votes
2answers
122 views

Will Web Components in HTML Add Too Much Complexity? [closed]

The way I've been accustomed to User Interfaces is to see everything as a div. Where a div is essentially a box and they can be stylized in CSS. <div class='container'> <div ...
2
votes
2answers
179 views

Is equating a variable to a function that takes the same variable bad programming?

Is it improper programming to set a variable equal to the result of a function that accepts the same variable? The languages in question here are c#, javascript and PHP (not sure if this works in C ...
6
votes
1answer
84 views

Strategies to maintain contract between mocks and APIs

Using a mock instead of hitting a 3rd party API like Postgres or Stripe can often be necessary when writing tests. A problem I've seen is when the API can unknowingly diverges from the data the mocks ...
5
votes
1answer
167 views

What is the most efficient way to implement a RESTful client app?

I am working on a web application for ranking some products based on some factors. The user send a search query to 5 restful webservices which by their turn send a response in a JSON format and ...
2
votes
3answers
174 views

Angular JS style guide when declaring variables

I'm new to Angular JS and working on a project with "legacy" Angular JS code. The code is about a year or half a year old. I often see stuff like this: var _link; _link = "http://localhost"; Or: ...
2
votes
1answer
83 views

Is it possible to not have a zero-indexed array with javascript? [closed]

I've been coming across some interview questions that mention within the question "... given an integer x and a zero-indexed array..." Is it necessary to mention zero-indexed array? What languages ...
0
votes
2answers
337 views

How to scramble a word, keeping first and last characters the same?

I have a task, which is to scramble a single word, whose size is greater than 3 letters. The scrambled word must not be equal to the original, and the first and last letters of the word must remain ...
4
votes
3answers
168 views

Javascript Closure Scope

I was reading the "Closures" section on the w3schools JavaScript tutorial and I don't understand how the last example works. http://www.w3schools.com/js/js_function_closures.asp The goal is to ...
0
votes
0answers
87 views

Using the Facebook Login button, how would I securely convey to my web app's backend that the user is authenticated?

Background: I'm building a web app using the most recent Facebook Javascript SDK to help with user registration and login. The backend is built in PHP, but that likely is irrelevant. The situation: I ...
44
votes
6answers
4k views

Does immutability hurt performance in JavaScript?

There seems to be a recent trend in JavaScript towards treating data structures as immutable. For example, if you need to change a single property of an object, better to just create a whole new ...
-1
votes
1answer
118 views

Inheritance hierarchy design approach - Javascript [closed]

For the below code, that creates inheritance hierarchy, function Animal(){ this.name = "Animal"; // toString is a function in the main Object that every // object inherits from ...
4
votes
1answer
321 views

Why is Array.prototype designed to be a fully functional array?

In the below visualisation, There are two array objects(cars & bikes) that are created with below syntax, var cars = new Array("Saab", "Volvo", "BMW"); var bikes = ["Honda", "Yamaha"]; whose ...
3
votes
0answers
94 views

Tips for optimizing javascript code. a year's worth of Dates

I am playing around with the date object, i made a function that generates a bunch of dates, and applies some function on each date. For a month's worth, it is fine about 2.5ms on my pc, ff and ...
5
votes
1answer
330 views

Will ECMAScript add classes to JavaScript? What does this mean?

I heard that some sort of class system will be added to JavaScript with ECMAScript and I find that a little confusing, because I've just finished reading a JS book, JavaScript, The Good Parts by ...
3
votes
1answer
122 views

Are there practical benefits from encapsulating JS inside class.create?

I am working on this web application that already has a mechanism that allows a developer to define server side JavaScript functions that can then be called by other server side JS code. There are ...
0
votes
0answers
59 views

Is There a Defense of Mutability in Javascript? [duplicate]

Immutability seems to be all the rage in the JS world these days (especially with the React contingent). However, when I try to weigh the pros and cons of using an immutability library, all I can ...
5
votes
3answers
322 views

Comparing two large strings to see how much they match [duplicate]

Is there an easy way of comparing any two different size of string text to see how much percentage they're alike? I'm trying this but I'm running into to this issue below. The left text area is the ...
2
votes
3answers
544 views

Why is JSX good, when JSP scriptlets are bad?

React.js provides JSX as an XHTML-like syntax for constructing a tree of components and elements. JSX compiles to Javascript, and instead of providing loops or conditionals in JSX proper, you use ...
0
votes
0answers
134 views

How does postback url works in campaign tracking systems?

my question is theoretical, a vague idea or some sort of algorithm will be great. I am building an advertising campaign tracker web app for a friend, yet i am kinda lost, i cant figure out how the ...
8
votes
1answer
321 views

Hoisting in Javascript === Compiling?

I came across an interesting perspective at a recent job interview. Hoisting in Javascript is about moving the variable declarations and function declaration at the top of the script. Can we call ...
2
votes
1answer
187 views

why are iframe-s so useful in HTML5 WYSIWIG applications?

<iframe> elements are documented as The HTML Inline Frame Element (<iframe>) represents a nested browsing context, effectively embedding another HTML page into the current page. ...
4
votes
1answer
199 views

What would break if there was an option to make undefined not convert to any other type in JavaScript?

The biggest issue I run into in JavaScript is silent typos. For example, the other day I had a variable inIframe. Somewhere else I typed isIFrame. 10-15 mins of debugging later I found it and changed ...
0
votes
3answers
145 views

Eliminating the bad cases in if to get a nicer code

I have read this link Should I return from a function early or use an if statement? and it triggered a conflict in my head. I agree that it looks nicer and cleaner and I guess that would be the way I ...
0
votes
1answer
51 views

Summing values from JSON end point based on category [closed]

I have a JSON end point for projects in a county. I am able to call a list of any of the object properties. What I want to do is to add together either all the values of budget property or the ...
0
votes
0answers
74 views

Algorithms for realistic path animation?

I have written some code that generates a set of paths of an object through a number of obstacles. You could imagine it as dozens of permutations of the path a formula one car takes through a twisty ...
17
votes
1answer
2k views

Why does Math.min work with a one element array

According to MDN Math.min accepts only numbers, and if one of the arguments is not a number, it'll return NaN. It's true that if we pass an array with multiple numbers we get NaN, like this: ...
2
votes
3answers
385 views

Are colons ok in a REST API?

I see many REST API examples with URIs like http://<whatever>/widgets or http://<whatever>/widget/123, for a specific thing. For most things I would just stick with the front slash, but ...
0
votes
0answers
53 views

Persisting and manipulating JS ArrayBuffer data on the server

My node.js app has to deal with (sometimes large; a few MB) tables of numerical data. I'm about to use JavaScript's native binary objects for this purpose (i.e. ArrayBuffer and friends), because ...
0
votes
1answer
1k views

Folder structure for app with Symfony 2, React, Webpack, and Sass? [closed]

I am creating an app that uses some components of Symfony2 along with React, Webpack and Sass. We will mostly code in PHP, with the other things adding functionality to our app. I'm having a hard time ...
0
votes
1answer
331 views

MVC Best practice mixing Partial View and JavaScript

I searched the internet and really can't find a good answer to this question. Imagine there is a View that contains a simple tab-element. Each tab-content is loaded dynamically (via ajax) when the ...
0
votes
0answers
242 views

Structured JavaScript Codes

A while ago I started working on a web application which has a lot of JavaScript code due to having a lot of client-side logic. Before starting, I had had a quick look at a couple of JavaScript ...
-1
votes
1answer
129 views

Synchronous architecture with asynchronous repository

In order to keep clean architecture of my node.js microservice I have controllers, services and e.g. repositories. I want a synchronous data flow: controller -> service -> repository -> service -> ...
1
vote
1answer
127 views

Is this the preferred way to do inheritance in JavaScript?

Hey there I'm not new to programming nor javascript but I'm new to the object oriented world of javascript as it differs from languages I know such as java, c# when it comes to object oriented ...
1
vote
0answers
27 views

Dealing with stubbed external dependency

In sut I should I have two kinds of dependencies to be stubbed: 3rd party dependencies (mongodb & co) and own dependencies: var async = require('async'), // This dependency should not be stubbed ...
2
votes
3answers
426 views

Is `isNaN`' a bad design or a has-to-be design with tradeoffs?

My first programming language is python. And recently I'm learning C and javascript. In javascript, there is a design which confused me a lot, default the function isNaN. Put aside its weird ...
1
vote
1answer
115 views

JavaScript securely retrieve data from server

I made an android application for the creation of personal timetables. I need two things for the user interface: The grades list and the student lists of the senior grades. To retrieve those, I made a ...
0
votes
1answer
214 views

Do any languages have syntax for promises? [closed]

I'm really glad that EcmaScript 6 has promises built into the language, but the syntax will still be quite wordy: new Promise(f).then(r => { ... }).then(r2 => ... }).catch(... I'm just ...