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
43 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
216 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
95 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 ...
2
votes
1answer
273 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: '...
2
votes
2answers
240 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 id="...
1
vote
2answers
94 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 ...
2
votes
2answers
220 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
200 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
32 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=()=>{ event.emit('onFuncBegin',...
3
votes
3answers
98 views

Ways to structure a program with 2 states

I'm working on some sort of a Level Editor but I'm not quite sure how I want to handle the two different states: The Editor state and the Player state. In this first state game elements can be moved ...
1
vote
1answer
137 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 ...
0
votes
4answers
173 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 ...
1
vote
1answer
53 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
43 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, ...
45
votes
8answers
7k 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
84 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 ...
1
vote
1answer
74 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 optional-...
1
vote
1answer
78 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 site!</...
0
votes
0answers
73 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 ...
-1
votes
3answers
190 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 ...
0
votes
0answers
32 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 ...
2
votes
1answer
119 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 ...
0
votes
3answers
175 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 } ...
0
votes
1answer
63 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 ...
4
votes
2answers
87 views

What does “initialize event handler” mean in this context?

In file1.js I read: // NOTE: initialize your app event handlers here, see file2.js for a simple event handler example // TODO: configure following to work with both touch and click events (mouse + ...
14
votes
3answers
337 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 ...
2
votes
2answers
58 views

Cleanly generating several 0-airty JavaScript functions with slightly different bodies

Say I have a bunch of JavaScript functions similar to: message = [“000”, “111”, “222”, “333”]; function F0(){ alert (message[0]); } function F1(){ alert (message[1]); } function F2(){ ...
1
vote
3answers
313 views

Where should I do localization (server-side or client-side)?

I am currently developing a new web application based on a rich JavaScript client which communicates with multiple REST web services on my server. That application is intended to be used in at least ...
0
votes
3answers
152 views

Which of these promise methods is considered a best practice?

I have a couple of async method that is basically a yes and no reply isUsernameAvalible() isOnline() isImage() yada yada... you probably get the point by now. As a demonstration... try to think of ...
-3
votes
1answer
104 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", ...
0
votes
1answer
123 views

Drawing a data-grid on canvas - whats the point?

To simplify my question let's assume for a minute that all users are using the latest version of Chrome to view a particular website. Using the latest libraries (Polymer for example), I can render a ...
5
votes
1answer
520 views

What does Google mean here when they say “don't copy and paste this code”?

Here is an excerpt from code from Google's recaptcha API (https://www.google.com/recaptcha/api.js): /* PLEASE DO NOT COPY AND PASTE THIS CODE. */ (function() { if (!window['___grecaptcha_cfg']) { ...
-5
votes
2answers
91 views

How do I make such a page that opens different link in web (PC) and different in mobile (phones)?

I am building a website that looks beautiful in Web but worst in mobiles. I want to build the same site but different designing for mobile. Whenever user opens site.com then it auto redirect to m.site....
-4
votes
2answers
148 views

How to find all occurrences of a variable within a source code?

The title is pretty self-explanatory. I have a minified JavaScript code (100k+ lines) and would like to find all occurrences of a particular variable so I could rename it to better understand code. Is ...
2
votes
1answer
91 views

Why does JavaScript console.log of objects sometimes show prototype/constructor pattern forever

I've always noticed this, but never actually understood what's happening here. I have a fairly simple object that I've put in a console.log. It has a seemingly never ending pattern of prototype -> ...
1
vote
1answer
196 views

How should I implement a full text search into my meteor web app?

I am making a web application using the javascript framework Meteor, which runs with mongodb. In the web app I have a db set up that holds individual video games in the documents. An example of this ...
7
votes
3answers
1k views

Is a function getting a value from another function considered pure?

I'm trying to figure out a way to handle default variable values when making functions without side effects and have ended up with the following: function getDefaultSeparator() { return ':'; } ...
-1
votes
4answers
209 views

Nested For Loops JavaScript

I have an app which gets data from the database (MongoDB) in JSON format. The returned data contains nested arrays and I want to access the values in the nested arrays. The returned JSON format looks ...
0
votes
0answers
48 views

Deciding on a Portable Platform (given a set of requirements)

Background Before asking this question, I researched this site and found the following 3 most similar questions have already been asked: When would using a scripting language within a larger program ...
0
votes
1answer
97 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 ...
11
votes
2answers
737 views

Benefits of Structured Logging vs basic logging

We're building a new app and I'd like to include structured logging. My ideal setup would be something like Serilog for our C# code, and Bunyan for our JS. These would feed into fluentd and then could ...
2
votes
2answers
108 views

When should I nest one module inside another?

Assume I'm working on a JavaScript application and make extensive use of the module pattern with one file per module. Now suppose I have two folders/modules: one for module A and another for module B. ...
1
vote
1answer
135 views

For Web front end, if there are 20 JavaScript files loading, how to track down the mouseover handler?

For Web front end programming, since any JavaScript can set up an event listener for "mouseover" or "mouseenter" for an element, if we are to track down what is the code that is responsible for making ...
2
votes
0answers
57 views

Dealing with conditional verification logic using guard assertion

I have parametrized test with 2 variants: NULL value and any NOT NULL value From this value is depends one assert: In case NULL it should be checked if object has field1 with value1 In ...
0
votes
0answers
58 views

How to effectively log while avoiding a bottleneck

I have a fuzzer for x86 Internet Explorer (in HTML) that I've heavily modified to have reproducible, determinisitic crashes (so that I may perform root cause analysis faster). I'm attempting to ...
3
votes
1answer
225 views

Best way to verify that a user has completed a task on another website.

We are developing a website for students on which they first have to fulfill specific tasks in order to use our service. The problem is, that those tasks are on another website, which has nothing to ...
1
vote
4answers
139 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, ...
4
votes
1answer
85 views

What is the best way to selectively load transpiled code or polyfills for downlevel browsers?

There's no escaping Internet Explorer 11 as it will be around until 2023 as the default browser of the most popular desktop operating system. Yet, Internet Explorer 11 will not get new updates to ...
2
votes
1answer
180 views

Redistribution in binary form - Copyright notice in Javascript

I want to distribute a single exe file, which is a simple http web server. This exe contains all the dependency html/js files (mostly licensed under MIT and New BSD) I really don't know if that's ...
23
votes
2answers
1k views

Why is passing large anonymous functions as arguments to other functions so widely accepted in JavaScript?

I have an opinion (which I am sure will be shared by some) that passing anonymous functions which contain more than a few lines of code, as arguments to other functions affects readability and self-...