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)

0
votes
1answer
115 views

JavaScript templating trick or treat?

I've recently been looking into using JavaScript for templating and I was wondering about the legibility of using this approach. I understand that JavaScript templating is a very common and much ...
1
vote
1answer
101 views

The Same Behavior for Boolean and Exception

The following code uses a boolean preference active: In the active state, it does an operation which could throw an exception. On this exception, it does fall back to the non-active state. let active ...
0
votes
2answers
57 views

JavaScript Callbacks before or after exiting function?

Is there a concrete reason to prefer executing callbacks to functions before or after exiting the called function? Example function doSomethingPossiblyAsync(callback) { if ...
-1
votes
1answer
95 views

Would a JS framework that automatically performs ajax requests in background be useful?

For the type of applications I usually develop (AngularJS single page applications that communicate with the server side based on the REST API) there are some requests done at the start for loading ...
1
vote
2answers
120 views

How far should encapsulation in JavaScript go?

I have a variable which I want to use in only one function. I can write my code like this: var theAnswerToLife = 42 var multiplyIt = function(x) { return theAnswerToLife * x } I have some other ...
4
votes
1answer
246 views

Reuse already fetched data for request

I have action that fetches user model from db to check access. Then I have method that in some cases requires same model. function checkAccess(req, res, next) { var data = ...
2
votes
1answer
50 views

Which IndexedDB data structure for Chrome app?

I'm on the way to build a Chrome app, dedicated to fulfill shop/marketplace orders. The orders come from marketplace APIs like Amazon MWS. The data is stored only in the app (with backup). The system ...
-3
votes
1answer
90 views

How to compare and replace value from two object inside array?

Here i want to replace price in data1 to price from data2, and it updated if the id is same. Is it possible to do that without nested loop? var data1 = [{ "id": "56e641d4864e5b780bb992c6", ...
2
votes
2answers
2k views

Should we (still) consider a synced XMLHTTPRequest bad practice?

As you may know, XMLHTTPRequest can be used synchronously or asynchronously, but synchronized requests have always been considered bad practice, and I've always agreed with that. Not only is the ...
1
vote
1answer
41 views

(react.js) when is it appropriate to call stores from non-container components

I believe most people are in agreement that using container components is a good practice - described in this popular post: https://medium.com/@learnreact/container-components-c0e67432e005#.qhw8yfodx ...
1
vote
1answer
47 views

Validating transaction codes with reference codes… Best way to encode the validation rules?

Good Day, I have a series of reference codes that my end users create during the course of the day. These reference codes correspond to a transaction code that is stored in a database. As of now, ...
2
votes
1answer
267 views

What should I call this utility function? Is something like it commonly used?

Suppose you want to combine some arrays of objects that have similar properties: var people = [{name: 'Jack', age: 10}, {name: 'Jill', age: 12}] var items = [{owner: 'Jack', name: 'pail'}, {owner: ...
0
votes
1answer
88 views

How to handle extra arguments in a JavaScript library?

JavaScript is the only language I've come aross which allows variable-length argument lists by default. A case where it would be helpful to detect too many arguments would be Mozilla's Add-On SDK's ...
0
votes
1answer
38 views

jQuery, deferrers and “if” conditionals

How could I simplify the following code? I suspect that it can be simplified by using the $.Deferred class, but I don't know how. if (condition) { $.get('url').done(function () { done(); ...
0
votes
1answer
202 views

My algorithm is too slow

Reposted from Stack Overflow - I think this is a more appropriate place to ask the question. I have an algorithm that for an integer x and a starting integer i such that 1 < i < x the next ...
0
votes
3answers
79 views

Design for a function to skip a step if called multiple times

Terrible title, but this is the situation I find myself in often and have not found a good design to make it nice. Lets say I'm working with Javascript and I have an object I am working on that needs ...
8
votes
2answers
538 views

Unit Testing a stateful framework such as Phaser?

TL;DR I need help in identifying techniques to simplify automated unit testing when working within a stateful framework. Background: I'm currently writing a game in TypeScript and the Phaser ...
2
votes
2answers
218 views

Are there any reasons not to ever use classes or ids anymore?

I sort of understand unobtrusive javascript. Even in my CSS now I hardly ever use classes or id's because I like clean, easy to read, uncluttered html files. For example, why use this: <body ...
-2
votes
0answers
26 views

How to dynamically limit the number of elements on a row in D3.js [migrated]

I'm fairly new to D3. I'm wanting to develop rows of rectangles with 4 rectangles each row. For example, if I had 8 data elements, it would draw 2 rows of 4 rectangles. If I had 9 data elements, it ...
1
vote
2answers
65 views

TypeScript/ES2015: Prefer `const` instead of `let` reduces readability?

ES2015 introduced the let and const keywords, which essentially have the same semantics apart from reassignment. (const can be seen as a final variable in languages like Java.) I see the point of ...
0
votes
4answers
166 views

Naming convention for method that may carry out an action

I have a method in that checks some conditions and if required, will carry out some logic to empty an array of 'selected' elements. Is there a standard way to name such a method? I was thinking ...
7
votes
3answers
2k views

Event-driven vs. 'reference'-driven programming (i.e. in JavaScript)

I haven't been able to find the appropriate terminology to search for content on the web related to what I'm asking, so I'm hoping someone on here can at least point me in the right direction. I'm a ...
2
votes
2answers
197 views

Is it a bad practice to use JSON strings as keys of objects?

On languages such as Haskell, most datatypes have instances which allow their values to be used as keys of structures such as Maps. JavaScript has reasonably fast maps, there called objects, but those ...
2
votes
2answers
64 views

Client-side Rendering vs JSP's for Spring MVC Front End Dev

Firstly, a note on the app I'm about to discuss: It's quite large, on the order of magnitude of a service app like Airbnb -- i.e., it's not just a static web page, it is a full web application. It's ...
0
votes
0answers
26 views

Event dispatcher and state

I'm using an event emitter similar to Node's, with the following pseudo code: event.on('onFuncBegin',(e)=>); event.on('onFuncEnd',(e)=>); let myFunc=()=>{ ...
44
votes
8answers
6k views

What are the drawbacks of making a multi-threaded JavaScript runtime implementation? [closed]

I've been working on a multi-threaded JavaScript runtime implementation for the past week. I have a proof of concept made in C++ using JavaScriptCore and boost. The architecture is simple: when the ...
1
vote
1answer
124 views

Returning functions within Javascript objects

After coming across Douglas Crockford's views on class-free OOP, and doing away with new and this in Javascript I tried defining an object with its own variable and function, and returning it in a ...
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 ...
0
votes
1answer
72 views

Can a browser script detect SSL MITM?

Is there a standard mechanism for javascript to detect TLS MITM? I'm looking for something along the lines of reading the fingerprint for a server cert out of the browser, and comparing to an inlined ...
1
vote
1answer
42 views

Template Literals (ECMAScript 2015 6th edition), are they worth it?

I recently found out about JavaScript's Template Literals, and they help a lot with readability. But would it be worth changing my code from now on to these Template Literals, or should I keep using ...
0
votes
0answers
34 views

Code structure for complex UI module with strongly bonded components

I'm trying to figure out a new approach in organizing my code structure. Let's say I have a single-page module which UI consists of: form with search filters, very interactive table (paginated, ...
1
vote
2answers
1k views

Multi-Threaded JavaScript? [closed]

I know, I know -- it isn't possible presently but my question is this: Would it be possible to write a browser plug in for the major browsers that enables true, multi-threaded JavaScript? It just ...
77
votes
23answers
7k views

How do developers find the time to stay on top of latest technologies? [closed]

I was a freelance web developer until circa 2004 when I started going down the management route but have decided to try to get back into development again (specifically JavaScript and HTML5 web/mobile ...
1
vote
1answer
55 views

Error handlers inside Promise.all

I'm looking at this piece of code and whilst it works, it feels wrong to me. I'm wondering if I am looking at an anti-pattern? The code starts with two promises, getAccounts and getTransactions. On ...
0
votes
6answers
486 views

Should i expect real world questions from interviewing agency? [closed]

I started coding almost a year ago. By "coding" I mean HTML(5), CSS(3), and only few times I implemented some AJAX and JavaScript. I am interviewing for a position that expects me to know HTML, CSS, ...
1
vote
1answer
64 views

Best practice for storing external text to then place in html

Sorry if I'm not explaining the question well in the title, I'm not sure of the correct lingo. Let me give you an example instead. So this is a normal HTML file. <span>Well to the ...
-3
votes
0answers
45 views

Making Div Tabbed Panels in Javascript

I have a website that needs to dynamically generate div tabs based on user input. Currently, this is the code I have to generate a single div: var div = document.createElement("div"); ...
1
vote
1answer
54 views

Java 8 Optional in JavaScript

I like the idea of Optional in Java which we can use to say that the object may or may not be available. I am now learning JavaScript and when trying to find an equivalent, came only across ...
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 ...
12
votes
3answers
281 views

Providing Local JS and CSS Resources for CDN Fallbacks

Given that CDNs are a Good Thing because they can serve resources closer to the client, the client can cache them, and you can reduce load on your own server. In recent browsers, loading resources ...
-1
votes
3answers
179 views

Are browser console errors 'compiler errors', 'runtime errors', or neither?

I was trying to communicate with a coworker about a JavaScript error I was being notified about in my browser's console window when I realized that I wasn't sure if I should refer to this as a ...
2
votes
2answers
160 views

Mapping different XML and CSV feeds

Not sure if this is the right venue to be asking this but here goes. A little background. I'm trying to build an ecommerce app that would allow sellers from other venues--like, amazon and newegg--to ...
2
votes
1answer
115 views

When making a change to a single table in our app, should we minimize the scope of our change, or follow best practice for css/jsp coding?

My co-worker has been assigned the task of editing one of our Java application's tables. She is almost done, but needs to make one final adjustment to the table - this requires her to add a CSS ...
5
votes
1answer
145 views

Set of specific values implementation vs. using some sort of generic set with advanced checks

I am working on a set implementation in JavaScript currently. This should kind of simulate generics as known from Java or C#. I need a mutable version of that (allows for adding/removing set values) ...
0
votes
0answers
26 views

iron-ajax chaining polymer

I am looking for a way to nicely chain promises in polymer. Now I define a method in my on-response to send the result of my first request to. Upon response, I fire my second request. This flow makes ...
0
votes
0answers
23 views

Syncing file data and form data uploaded at separate times

I have a web application where users can upload office documents. In addition to uploading files users also specify extra information about them that's not contained in the files themselves but is ...
0
votes
3answers
99 views

Does setTimeout() really execute in parallel?

Consider following JavaScript code: function foo(ary) { // some long operation on ary } function bar(ary) { // some long operation on ary } function baz(ary) { // some long operation on ary } ...
3
votes
1answer
353 views

is this a valid javascript design pattern when many instances are required?

I have some code that I'm refactoring, right now its just a list of functions, primarily jQuery. The code is a form builder. The user adds sections, questions etc using jqueryUI drag/drop/sort. They ...
0
votes
1answer
54 views

Should models be returning data directly to the client, or to the controller instead?

Disclaimer: This is my first time: using node, creating a REST API, and trying out MVC server side. (so, just statistically speaking, I'm probably doing something wrong ¯\_(ツ)_/¯) I'm working on ...
1
vote
4answers
117 views

How and where to test if the JSON request objects generated by the front-end is valid

We have built a complex Angular application that sends multiple HTTP request to a REST service that is also built in house. Since both the frontend and the backend is being developed in parallel, ...