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
0answers
9 views

How can I _read_ functional JavaScript code?

I believe I have learned some/many/most of the basic concepts underlying functional programming in JavaScript. However, I have trouble specifically reading functional code, even code I've written, and ...
0
votes
0answers
55 views

Should I use a closure instead of a class when I only have one method?

Lets say I have a JavaScript class that takes a whole lot of settings in the constructor, and then only have one method that the user of the class might want to call multiple times. Here's an example: ...
0
votes
1answer
71 views

I'm building an app with Node, Express, and MongoDB. Is AngularJS necessary?

Node, Express, and MongoDB are really connected so I can understand why they are frequently used together. For a web app of medium complexity, can I get away with only using HTML/CSS and EJS for the ...
0
votes
1answer
26 views

Three.js Screen Tear

Using Three.js Revision 51 (Yes I know the latest is 84) I am getting a screen tear at random times on the load of my page. It seems like it's 50% whether it's a hard refresh or a fresh load of the ...
-1
votes
0answers
46 views

Special Load Testing Scenario - which way should I go? [on hold]

I need to load a page, wait for the execution of a javascript function called from it (on document.ready) and log what the function returned. I know how to do this with nightmarejs for a single ...
1
vote
2answers
77 views

Avoid wrong variable on branch commit

Our frontend web software contains, inside a file called url.js a variable used as URL root for REST webservices. var url = "https://devappserver:8080"; During development on developer PC, for ...
0
votes
0answers
16 views

Node.js - Native promises executing individual parallel batches of items one at a time

I'm a newcomer to using Promises, so I'm trying to figure out how to use them for a task, but I'm having a hard time mapping what I read in the simple examples on the internet to this task. I have ...
4
votes
2answers
59 views

Tracking state changes based on duration of time in state

I've been building a monitoring system that checks whether a device is alarmed or not, and if so, sends notifications to relevant users based on how long a device is in a particular state. Here's an ...
1
vote
3answers
113 views

Should conditionals be embedded in the function whose execution is contingent on them?

I have a large data structure that is about to be persisted to the database. Before that can happen I have to validate it and then update a bunch of it's properties based on various specific ...
1
vote
2answers
111 views

Microservices, browsers and HTTP requests

In the old days we used to create a single .gif file for the entire application to avoid too many trips from the browser to the server. Similarly, we used to combine different types of information in ...
1
vote
2answers
28 views

Html file input field add files? (instead of replace)

I'm trying to create a Html file input field which can add multiple files to the form, instead of replacing existing chosen files. This is the basic file input element for uploading multiple files: &...
4
votes
2answers
141 views

Two “flavours” of undefined in JavaScript shown by trying to map them

Why does the 1st map method below treat element #2 as undefined but the 2nd map method does not? const a = [undefined,,42]; // Note the two consecutive commas. console.log(a.map(x=>x)); ...
-6
votes
0answers
43 views

How web-developers display items of an E-commerce site? and how can we make clients capable of using our Newly Made Website? [closed]

I am really confused on how web developers display their items on a E-commerce site. I know I can use tag, but what about my Client? If my Client can edit or even read code. The client won't be able ...
2
votes
0answers
176 views

Does using returnTrue() or returnFalse() functions a code-smell?

I was trying to understand how jQuery's cross-browser events work, when I noticed these two functions in the source code: function returnTrue() { return true; } function returnFalse() { ...
-4
votes
1answer
103 views

Did GO embrace any language construct introduced in Java?

GO has embraced, 1) JavaScript/Python language constructs, Higher order function Closure Slicing Range operator Anonymous function(inner function) Provides abstractions ...
3
votes
2answers
162 views

Javascript: using magic object keys

I just wrote a function and I'm not sure if it is a good idea. The motivation is, I'd like to store some internal bookkeeping data along with my business data in one big happy javascript object. ...
-1
votes
0answers
41 views

WebGL loses context when heap grows too large? [on hold]

Bear with me as the world of optimization and resource allocation is a new space. I am creating a custom, interactive WebGL visualization that is browser based and will be displayed as a projection on ...
2
votes
1answer
329 views

Why Functional Programming - When is it okay to get rid of efficiency for readability?

I was reading Death of for-loop article, and I thought maybe I should timeit the codes. I created this benchmark at jsperf which clearly shows that map-filter approach is about 90% slower. So, why is ...
0
votes
0answers
64 views

How do you handle time unit constants (second, minute, etc)?

I've been writing a lot of time related code recently, and in various files, I always end up re-defining things like var SECOND = 1000; var MINUTE = 60 * SECOND; This gets frustrating quickly. So I'...
0
votes
0answers
50 views

Architecting a multipart React application

I am working on an web application for playing simple games (like hearts) online. It's built on top of Feathers and React. It's going well and I have built several games on top of it. When I began ...
3
votes
3answers
200 views

Should I reduce event listeners by making functions more complex?

An example would be if you had multiple inputs, each of which effect a completely different process, (perhaps one changes a div's width, while another sends ajax request for predictive search), would ...
0
votes
1answer
72 views

What are security risks of WYSIWYG HTML/CSS/JS editors running as web service?

I am currently implementing WYSIWYG editor that will be available on the web, what are the main security issues I should tackle? The editor currently works that when user is done typing, the text gets ...
5
votes
1answer
174 views

Is loading the same .jpg in different qualities a waste of data?

I'm building a web site and I want to use a big background image. Because of speed considerations, I thought that it would make sense to send a low-res version of the image the user first (for fast ...
5
votes
2answers
185 views

How to create a safe namespace for my application in JavaScript

I'm working on an application in the browser and I would like to make sure that my code does not conflict with code from other libraries or with possible calls added by browser manufacturers in the ...
7
votes
3answers
164 views

Are we “allowed” to use methods on JavaScript maps (the data type) and if so are there any new rules?

JavaScript maps (the data type, not the array method) seem set up to accept data (key/value pairs) but not necessarily methods. At least they're not advertised that way. However, we can put methods ...
0
votes
2answers
87 views

Liskov's substitution principle and prototypical languages

Do prototypical languages provide a remedy from Liskov's problem? So the way I see this is: a subclass is very tightly coupled with it's superclass and this creates subtle side effects when ...
41
votes
9answers
6k views

Is a JS Boolean having custom properties a bad practice?

In JS you can return a Boolean having custom properties. Eg. when Modernizr tests for video support it returns true or false but the returned Boolean (Bool is first class object in JS) has properties ...
3
votes
0answers
95 views

How should Rails be set up with an SPA client like Aurelia?

Let's suppose I have a backend with API-only Rails. There is also a Javascript single-page application (Aurelia, but could be something else) talking to this API. Should I keep these together, in the ...
4
votes
1answer
161 views

What are the benefits of encapsulating conditionals (in functions)?

According to this clean-code guide you should encapsulate conditionals: function shouldShowSpinner() { return fsm.state === 'fetching' && isEmpty(listNode); } if (shouldShowSpinner()) { /...
2
votes
0answers
81 views

Drag and Drop with animations

This is more of a theoretical question which I hope is okay!? I want to code my own drag and drop jQuery plugin, but i'm wondering the best way to go about structuring my code and actually doing it. ...
1
vote
1answer
44 views

How to avoid fetching additional informations when instantiating objects

I'm creating an HTML5 game using javascript and have got some problems during the first instantiation of the objects of the scene. Scenario Self-written 2d game engine that supports multiple ...
0
votes
0answers
65 views

WebApp MVC Architecture Design Question

This is a simple architecture design question that I thought of when building a spring MVC web app. The front end is javascript and the back end that does the heavy lifting is Java. The application's ...
0
votes
1answer
55 views

Animations and React — is it bad practice to mix them?

I have been in arguments with programmers that mixing elements with animations and react is very bad practice, and that all animations should be in a style sheet because that is something ...
5
votes
2answers
98 views

Permission system using PHP and JS

I'm developing an admin dashboard with different areas, where different users may have different permissions. For example: News John: edit, view, add, remove; Carlos: edit, view; Mario: --; Support ...
3
votes
2answers
94 views

Making parameters required by using a function call as a default value in JavaScript

ECMAScript 6 introduced default parameters. The default value can be any expression, so you can use it to make a function throw an error when a parameter is not supplied: const mandatory = (name) =&...
1
vote
2answers
203 views

How come language designers don't upgrade their global functions?

For example, when working with arrays there are methods like indexOf() that works like this: if (array.indexOf("something")!=-1) { // do something or nothing } Why hasn't someone made a contains ...
4
votes
2answers
83 views

Is there any good/fundamental reason that Python classvars, and JavaScript prototype inheritance, don't mutate the parent on assignment?

In Python, if you have a classvar, it's accessible from an instance, but if you set the variable on the instance it doesn't actually change the classvar, rather it assigns a new name which shadows the ...
3
votes
1answer
104 views

Why would I use es6 Set prototype -> 'entries'

According to mdn's "Set" documentation, entries is provided as a convenience method ...to keep the API similar to the Map object, each entry has the same value for its key and value here, so that ...
2
votes
2answers
86 views

How to validate ajax request comes from correct page and is not tampered with?

I am building a simple Q&A app with PHP, HTML and JS. I have three tables: users,question and answers, each table has it's own primary key and questions and answers both have foreign key ...
0
votes
0answers
41 views

Dividing up a large class into tasks - passing `this` when creating helper classes

For classes that expose an interface to the outer world, I observe that callbacks are used as a standard interface. For child helper class objects that are tightly integrated to its parent, I want to ...
0
votes
0answers
98 views

Optimizing a client-server visualization that runs out of memory

I have a visualization (shader-based) that I'm running in a Chrome browser. Recently I've been running out of memory after periodically refreshing the pool of data from the server, or if I make the ...
0
votes
0answers
123 views

How to refactor this confusing javascript architecture?

A while ago I inherited the front end on a product at work and I've been building further atop a somewhat confusing architecture of javascript. I finally have the time available, and the will from ...
0
votes
0answers
33 views

Versioning Practices for Javascript SPA Application

I've developed an SPA using AureliaJS. We use team Foundation server to service our source control, but that doesn't really help with good versioning practices. For instance, with our WPF applications,...
16
votes
5answers
256 views

Is rejecting a Promise only for error cases?

Let's say I have this function authenticate that returns a promise. The promise then resolves with the result. False and true are expected outcomes, as I see it, and rejections should only occur in an ...
7
votes
4answers
505 views

What is the benefit of having “no runtime exceptions”, like Elm claims?

Some languages claim to have "no runtime exceptions" as a clear advantage over other languages that has them. I am confused on the matter. Runtime exception is just a tool, as far as I know, and ...
1
vote
1answer
95 views

Finding the minimum transaction

Given a list of transactions like: A -> 10 to B B -> 10 to C The naive way to settle the transaction would be: C owes 10 to B B owes 10 to A But the same transaction could be settled by: C ...
1
vote
1answer
72 views

Is this a Proxy or Decorator pattern implementation?

The way many design patterns are described in the classical literature is somewhat different from their implementation in dynamic languages such as Javascript. The presence of some features like ...
5
votes
3answers
234 views

Functions that contain single statement?

Is it OK to have functions that have single statements? I usually make functions that have single statements. I believe these increases code readability and i am able to write code faster as they ...
2
votes
2answers
266 views

When should I use “value” as an argument name? [closed]

I'm building my own utility functions to master ES6: const contains = (array, value) => { return array.indexOf(value) > -1 } const keys = (object) => { return Object.keys(object) } ...
8
votes
1answer
186 views

Module Requiring vs Dependency Injection in Javascript

These days a question popped out in my mind: Does the way we Javascript go against almost everything that is considered a good practice in traditional Software Development? I have a series of ...