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)

44
votes
6answers
5k 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
121 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 this....
4
votes
1answer
329 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
102 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
335 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
127 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 ...
5
votes
3answers
443 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 ...
5
votes
3answers
934 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
185 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
344 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
208 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
213 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
150 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
57 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
77 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: Math.min([...
2
votes
3answers
466 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
67 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 they'...
0
votes
1answer
2k 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
492 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
252 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
142 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
129 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 apsects....
1
vote
0answers
31 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
434 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
123 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
221 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 ...
2
votes
3answers
217 views

What is the most readable way of passing arguments to the function? [closed]

I'm using JavaScript but the question can be generalized to all the languages. In a nutshell - I'm checking if a browser connecting to my site is a microwave and cater for that accordingly. What ...
2
votes
2answers
76 views

Design architecture advice on relation between objects and singleton JS

I would like your feedback regarding some best practices on design relationship between objects, specially when a singleton object is involved. Let's imagine I need to simulate a Shop with Customers....
1
vote
0answers
622 views

Multi-page application using angularjs

I want to create a multi-page application using angularjs, because i want to make use of a lot of angularjs functionality, like two way binding, form validation, AJAX handling, etc. But I read from ...
4
votes
2answers
114 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 ...
8
votes
2answers
540 views

Doesn't dependency injection push the testing burden further down the chain?

I'm learning about dependency injection and while I can see the appeal of it when writing functional libraries, I fail to see how it solves anything when you'll also be the one using the libraries. ...
3
votes
1answer
249 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 ...
2
votes
1answer
158 views

Can JIT compilation be non-deterministic?

I have been profiling a lot of javascript today in writing a firefox js engine bug report, and started really noticing the slight differences between JIT compilations. While there are some obvious ...
1
vote
2answers
1k views

UML modeling angular controllers / factories and services

I have to create UML documentation for my upcoming project. Now I have previously worked with Java which as an object orientated language is relativly easy to design UML class diagrams for. For my ...
2
votes
1answer
171 views

In garbage collecting languages (JavaScript), can I securely overwrite data?

Realizing that garbage collection and memory management is implemented differently in different environments for sake of simplicity this question will focus on JavaScript (either V8 or Seamonkey). I ...
1
vote
1answer
4k views

Rendering partial View in MVC

i am not so familiar working with partial Views. The reason behind that is that I really do not have the basics of Jquery/JS/Ajax. But I recently found through some SO post that a partial view can be ...
2
votes
1answer
94 views

How to best futureproof frontend code as server response evolves?

I find that in the early stages of a project the structure of the data returned by the server can change quite frequently as the data model changes. For example, if I'm building an application that ...
-3
votes
1answer
266 views

Simple Javascript Validation not working [closed]

I am trying to do the following: HTML Code <body> <form name="myform"> <table> <tr> <td>First Name:</td> <td><...
0
votes
4answers
692 views

How is an interface used in Dependency Injection?

I'm working on a simple DI library, and on the subject of using services through interfaces, I can't find the usefulness. Perhaps it's because I dont fully or properly understand how an interface ...
1
vote
0answers
99 views

ModelState Validation vs JQuery vs Remote

I was stuck with some validations for quite a while. I have been thoroughly searching the internet to find ways to apply the validations I require. I came across many methods for validations even ...
2
votes
2answers
381 views

Justifying programmatically ensuring frontend and backend validations are synchronised

Like many Javascript-based rich web apps these days, I have some complicated validation rules implemented on the front-end. The same rules are supposedly repeated exactly on the Java backend but I ...
0
votes
0answers
134 views

Does the term “readability” refer also to the transparency of code functionality? [duplicate]

Question: Does the term "readability" refer also to the transparency of code functionality? For Example: I read that a downside of Dependency Injection is a sacrifice to readability. The idea being ...
2
votes
1answer
171 views

TDD/BDD - Properly defining tests, adjusting tests, putting describe blocks inside it blocks

I am coming around with TDD/BDD. I am a bit confused though, when it comes to initially writing my BDD tests and then adding more tests after the very broad tests. For Example, lets say that I am ...
0
votes
1answer
89 views

Does this structure satisfy the terms of the Inversion of Control principle?

I'm trying, as a test, to create Dependency Injection from scratch in JavaScript. Consider the following code structure, which outputs an Alert: Does it satisfy the terms of the Dependency Inversion ...
3
votes
2answers
315 views

What should a Dependency Injector look like in JavaScript?

I'm studying Dependency Injection in JavaScript. I've learned what I need to accomplish, according to Wikipedia, The client delegates to external code (the injector) the responsibility of ...
1
vote
0answers
73 views

clone(serialize) v. serialize(clone)

My objects serialize() method is dependent on a call to its clone() method, because of its options to get rid of unwanted data without changing the original instance: serialize: function(opt_filters) ...
1
vote
1answer
366 views

History of VanillaJS

When did the trend of saying VanillaJS to refer to pure JavaScript come into widespread. Is the website Vanilla-js the discoverer of the term VanillaJS or was this term used even before the launch of ...
1
vote
0answers
59 views

Advice on streaming architecture [closed]

I want to be able to stream my desktop to 1 other person (and in the future to possibly more people). The stream should be watchable from a browser or a mobile app (iOS, Android, Windows Phone) ...
1
vote
5answers
559 views

Is this taking DRY too far? [duplicate]

A colleague and I are working together on a Meteor app. One of us thinks that the following code in two places should be wrapped in a function to avoid duplication -- the other thinks that it leads ...