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
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 ...
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 ...
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 ...
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 ...
2
votes
2answers
123 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 ...
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 ...
-1
votes
1answer
130 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 -> ...
4
votes
4answers
17k views

Falsy values vs null, undefined, or empty string

I've worked with jQuery over the years. However, recently, I've found myself getting deeper into the JavaScript language. Recently, I've heard about "truthy" and falsey values. However, I don't fully ...
3
votes
0answers
351 views

How to avoid module dependency chain nightmare caused by transitive dependencies?

Many (most?) AngularJS folks seem to advocate for breaking AngularJS apps up into many modules. Brian Ford in his blog already states that packaging by layer (controller, service, etc.) is a "silly" ...
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 ...
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 ...
0
votes
1answer
306 views

Why does a lot of Angular source code avoid enclosing the contents of a file in a closure?

I am assuming because it is a standard practice in the Angular world that, any sort of module system has to be wrapped as an Angular module and angular should be the only global variable used which ...
3
votes
1answer
182 views

Best-matching comparative values using all items in array

I have two arrays of objects (items) in the exact same format. Each item represents a wager, and each array represents one of two outcomes for that wager (ex: Team A vs Team B). Both arrays look ...
-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 ...
1
vote
3answers
299 views

Javascript Password Security [closed]

I am having difficulty with the answer provided here, but I couldn't understand how to implement it. My code is pretty much identical: <script language="javascript"> function check(form) { ...
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 ...
24
votes
2answers
9k views

What is ASM.js and what does it mean for everyone?

I'm starting to hear rumblings about this project called ASM.js. Currently their web site is terrible and confusing. Here's what I know from my research on the web. It is a subset of JavaScript that ...
4
votes
2answers
111 views

Check in which region is a geoposition Marker located in

I use Mapbox to display some moving markers over a map with several polygons drew over it (feature layers). I have serveral markers (~1000) and multiple feature layers (polygons ~200) that represent ...
3
votes
1answer
123 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 ...
3
votes
1answer
232 views

Best practice for angular service return value

I have a number of angular services (e.g. a user service) which make various HTTP calls and I'm wondering what the best practice would be for handling errors. For example, I could do: function ...
4
votes
2answers
295 views

How to avoid circular patterns in Node?

I'm new to Node and JavaScript (well, asynchronous programming in general) and I noticed when I was working on a project that the following code is a circular pattern and that these are bad practice ...
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
323 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 ...
6
votes
2answers
340 views

How can I go about testing this javascript?

I'm working on a project that has me responsible for testing out some software that scrapes a web-page representing an input form, and generates a mobile friendly version of that page. This is ...
3
votes
2answers
229 views

Naming self or this something else, a good idea?

I'm finding that my code becomes more readable when I make a local reference to this/self, and/or call it something that makes sense in the context. "self" or "this" doesn't really indicate what kind ...
3
votes
1answer
735 views

How do people develop emulators?

I hope this is right area on Stack Exchange to ask this question. People out there have built emulators for every game console but I don't understand how they do it. I consider myself (and have the ...
0
votes
0answers
136 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 ...
42
votes
8answers
6k views

How do I get started with HTML5? [closed]

What is the recommended workflow to learn HTML5? What tools should I install? What SDK? Where to start? How to test? How to debug? What do I read? I understand that what is often labelled as "HTML5 ...
37
votes
6answers
41k views

try-catch in javascript… isn't it a good practice?

There is a provision for try-catch block in javascript. While in java or any other language it is mandatory to have error handling, I don't see anybody using them in javascript for greater extent. ...
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
52 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 ...
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: ...
1
vote
1answer
480 views

JSP in Javascript file or multiple AJAX requests

I've been thinking about how I want to load my data for some checkboxes in an AngularJS app. I'm generating multiple checkboxes based on 2 JSON objects that are currenty hard-coded in the a Javascript ...
5
votes
1answer
1k views

Importing plain javascript libraries in an AngularJs application

I am working on an AngularJs project which is getting bigger very fast. Currently I need to store some user data, so I was using $localStorage for Angular. But I had a problem, as the application is ...
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 ...
2
votes
1answer
219 views

How to avoid tying these two methods together with global mutable state?

I'm in the process of reading Code Complete 2 and learned that using global state is a no-no. What can I do to avoid using global state in this situation? Some background information: I have two ...
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 ...
2
votes
2answers
309 views

Declaring JS Functions in Two Ways : What's the Benefit?

I've come across JS code in which I see functions being declared in two different styles: Method 1 function doSomething(){ alert('This is one way of declaring a function'); } Method 2 ...
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
334 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 ...
1
vote
3answers
361 views

Multiple Canvas in the Browser — How to Proceed?

Here's something I wrote ages ago as Java applet. I want to convert it into JavaScript and run in html5 canvas in the browser. From what I can see, canvas makes the most sense here. (SVG / DIV ...
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 ...
2
votes
0answers
106 views

Hot swapping files and metaprogramming with front-end JavaScript

I was inspired by a video on hotswapping JS files with React + Webpack for the web. I started trying it out with React + Backbone + RequireJS. Seems to work, as long as I stick to the stateless parts ...
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 ...
3
votes
1answer
174 views

Managing Massive Updates with Resource Access

I have a number of data servers that are pushing data to a main server as in this kind of architecture: These data points (points for short) are updated randomly from each server. On the server, ...