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)

3
votes
2answers
181 views

Is it bad practice to use hyphens in JSON keys?

I see a lot of questions revolving around accessing JSON keys that use hyphens (kebab-case), but now I find myself wondering should I just stick to camelCase or snake_case in my keys. I know hyphens ...
0
votes
2answers
82 views

Is it bad practice to verify arguments passed to a function? [duplicate]

I find myself writing a lot of functions whereby the first few lines "verify" the arguments, that is, they typecast, check falseness, range, etc. before doing any work. The main reasoning for this is ...
1
vote
2answers
67 views

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

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, there are 15 ...
-1
votes
0answers
21 views

What is Python Django and Flask? [on hold]

I understand the role of HTML, CSS and JavaScript in making Websites. One is for styling and the other makes it interactive... But what does Python Django and Flask do?
-4
votes
1answer
34 views

Website Development - W3 Layout [on hold]

I tried to download a free template from W3layout but the file is corrupted. So I tried to pick up the CSS, HTML and JS files by diving into the source code. I used this link to pick source files ...
-1
votes
0answers
21 views

Does it make sense to use namespace pattern in ECMAScript 6? [on hold]

In ECMAScript 5 of JavaScript it was common approach to use namespaces in your code. (implementations of namespace in JS). ECMAScript 6 standard declares modules. But still there are many projects ...
1
vote
0answers
12 views

Linking service and factory functions to controller $scopes in Angular

I'm trying to keep my controllers as thin as possible, so I keep my domain logic in services and factories. When I need to call a function in response to a user action like a click I assign the ...
1
vote
1answer
407 views

How do I make a JavaScript promise return something other than a promise?

I have a spec from a client for an implementation of a method in a module: // getGenres(): // Returns a promise. When it resolves, it returns an array. If given an array of genres, ['comedy', ...
0
votes
0answers
39 views

Embedding custom business logic using Javascript in Java application

We have an application where the front-end is completely rendered dynamically. The web page is stored as JSON in the database. A simple JSON to display input field with a label is as follows: { ...
-5
votes
0answers
35 views

Twitter login through javascript [on hold]

I want to write only JavaScript code for twitter login and fetch logged user information like screen name , user link URL , user location etc.
1
vote
1answer
594 views

How do we structure our JavaScript so that it is easily editable, testable, and can make calls to render a view without knowing specifics about it?

I am working on a web application that displays some data and uses JavaScript. Right now, we are serving up parts of our JavaScript code (to display certain types of information, that is, "Render a ...
-1
votes
0answers
83 views

Packaging a HTML,JS,CSS project within an application for security.

We have a project which is designed with html,css and JS. For demonstration purposes, we have integrated the project inside a JavaFX app in the webkit browser and from there we are just loading the ...
-3
votes
0answers
27 views

Tracing code flow, on very large projects [duplicate]

I am having a project in javascript, with many thousands lines of code, spread across hundreds of files. I am looking for a way to get familiar with the structure without having to debug and add ...
0
votes
1answer
54 views

What are the advantages of RxJS Observables over promises? [closed]

It seems to me like Observables are basically wrappers for promises with some helper methods. It also requires a huge library to go along with it. Do the benefits of these helper methods outweigh the ...
3
votes
1answer
111 views

I feel like the more I improve the structure of my program I am writing a DSL [closed]

My project started out as spaghetti code. The more DRY and extensible I make my code, the more it looks like configuration files and code than runs them. Is that a good thing or does that mean I am ...
1
vote
2answers
44 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 ...
0
votes
1answer
48 views

Why is the “global” RegEx flag in JavaScript considered a property of regular expression itself?

In JavaScript, RegEx objects can be instantiated with flags such as g for global matching and i for case-insensitive. Intuitively, it makes sense for i to be a property of the constructed RegEx, ...
1
vote
1answer
15 views

In what sense does the complexity of class hierarchies motivated by static type checking?

For example, from the book JavaScript: The Good Parts, I stumbled upon this passage: Much of the complexity of class hierarchies is motivated by the constraints of static type checking. ...
-1
votes
1answer
60 views

React.js + Flux, immediate response during history back/forward

In Instagram (web), when you click back/forward arrows - I've noticed that the content isn't loaded from the server and it immediately show up. After reading the docs on react.js + flux, I had this ...
30
votes
5answers
6k views

Why do we need enums in dynamically typed languages?

I was reading some code here and saw that an enum is used to store names of html tags. Why do we ever need to do this? What benefit do I get using this strategy? I know that how useful enums are in ...
41
votes
5answers
4k views

How to avoid typical “dynamic language mistakes”?

I've recently poured a couple of hours into JavaScript because I wanted to benefit from the massive userbase. Doing that I have noticed a pattern that most people attribute to dynamic languages. You ...
-3
votes
0answers
51 views

Javascript object comparison [on hold]

Why is obj != obj in following context: var variable = {} //any non-primitive datatype ([], {} /()/, function(){}) var obj = {a: {}} //can also be: var obj = [{}] alert(variable ==(=) obj.a) //in ...
2
votes
2answers
170 views

How to avoid circular reference in OOP Javascript?

I have a problem while working with entity framework in JavaScript. I have two classes Table and Column Class Table { Columns: Column[] } Class Column { Parent: Table } Everything works fine until ...
243
votes
7answers
19k views

Does using == in JavaScript ever make sense?

In JavaScript, the Good Parts, Douglas Crockford wrote: JavaScript has two sets of equality operators: === and !==, and their evil twins == and !=. The good ones work the way you would expect. ...
0
votes
0answers
28 views

Help me understand this flow for recursive function [duplicate]

This recursive function blows my mind a bit because it executes the recursive calls until it hits 1. It returns n, but afterwards it does the multiplication below it four times and returns the final ...
2
votes
2answers
95 views

Image resizing client side vs server side

When uploading a lot of images to a server, to minimize the space taken by the images, is it better to resize the images before sending to the server or upon receiving them? It seems to me that ...
13
votes
1answer
5k views

Confusion about dual license (MIT/GPL) javascript for use on my website

I've read all of the posts I can find on this and I'm still not sure of the answer. I'd like to use a jQuery plugin on my website that is dual licensed under MIT and GPL. Does the dual license mean ...
2
votes
4answers
177 views

Understanding closures

I'm reading the JavaScript guide on MDN and trying to understand the usefulness of closures. This sentence helped me the most, "In other words, the functions defined in the closure 'remember' the ...
-3
votes
0answers
81 views

Password strength feedback

I'm creating a password checker. The user is entering the password in the check.php form and then the password is saved using another php add.php To validate the different policies, like character ...
0
votes
1answer
54 views

One time use token Mobile / Desktop linking. How to?

I want to know if there's a way or known way to implement this: Lets say I have: a C# WinForms program a Javascript Mobile Application (Android / iOS) What I want to do is: for my C# ...
-1
votes
0answers
50 views

Working with JSON arrays with no keys in angularjs

I'm working with a cube that is exporting arrays that are essentially crosstabs of two columns with a third value indicating the value of the cross section. I'm pretty new to angularjs (and JavaScript ...
-1
votes
0answers
52 views

javaScript eval() and window[].call() security

Before I begin, yes I know eval() is evil; but I have a rather specific use case. I'd like to make sure I'm correct in thinking this won't be an issue. The program must evaluate arbitrary math ...
18
votes
6answers
24k views

Advantages and disadvantages to using XAML/C# or HTML5/JavaScipt for Metro apps? [closed]

I was just wondering if there are any major advantages or disadvantages to using either XAML/C# or HTML5/JavaScript for Metro Apps.
2
votes
2answers
167 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 ...
5
votes
2answers
156 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
1answer
42 views

Scaling up with zeromq REQ and nodejs

In the excellent book Node.js the right way the author shows this example: const fs = require('fs'), zmq = require('zmq'), // socket to reply to client requests responder = ...
4
votes
2answers
174 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 ...
0
votes
0answers
37 views

How can PhantomJS take a JavaScript file and use it to drive the WebKit?

I have read a lot of documents and wiki pages about PhantomJS but still don't understand, how can PhantomJS take the input JavaScript code to drive the WebKit? Take the code from PhantomJS Quick ...
2
votes
1answer
81 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 ...
0
votes
1answer
41 views

Performance of changing img src via jQuery or adding as a class

Background I've been doing a bit of image manipulation recently in PHP/JS. The basic functionality is such: Web page loads, an <img> tag points to a PHP script which generates an image "on the ...
3
votes
1answer
386 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 ...
2
votes
2answers
97 views

It it a better to have the expected return at the beginning or at the end of a function?

This is a function that searches child nodes recursively until it finds one that is a text: _.findPrevText = (node) => { if (node.nodeType === 3) return node return ...
0
votes
1answer
132 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
107 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
69 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 ...
4
votes
1answer
248 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 = ...
-3
votes
1answer
95 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
51 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 ...
2
votes
1answer
270 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: ...