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)

2
votes
1answer
2k views

Randomly Generate Points in a Spiral Motion using Javascript

So I have a javascript program that currently gets random points, it generates a random x,y,z value around the center point, within the radius r var maxArms = 3; var i = 0; var color = []; ...
2
votes
0answers
54 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 ...
4
votes
1answer
84 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 ...
9
votes
4answers
5k views

XSLT equivalent for JSON

I was interested in finding (or if necessary developing) an XSLT equivalent for JSON. As I have not found any, I was considering the possible query language to use for matching JSON paths so as to ...
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
2answers
285 views

Shared data in functional programming

I have been working on a project in JavaScript which requires a data structure (read only), to be shared between two functions. var mySharedData = ['hours', 'minutes', 'seconds']; Now I have two ...
4
votes
2answers
609 views

Local Updates in Persistent/Immutable Data Structures

I'm getting into ReactJS and am intrigued but also confused about persistent data structures. I love the idea, but I'm not sure how to take my MV*, Mutable, Observable Bindings experience in designing ...
2
votes
0answers
104 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 ...
2
votes
1answer
160 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-...
2
votes
0answers
44 views

How to architect rule matching with multiple conditionals and outcomes

I'm working on allowing my users to create their own ruleset for data that's coming in. All of the data below is sample mock data and not in relation to our product. Example of a rule (there can be ...
5
votes
2answers
227 views

Respectable design pattern for making node modules flexible/testable?

I am looking to get some input from some more experienced testers than what I am. :) I am trying to make my node modules testable, allowing for dependency spying/stubbing/mocking without the need to ...
2
votes
2answers
105 views

Generate pips on a die based on value

Is there an algorithm to generate the pips on a die or domino? I know that there is usually an odd number of columns and even number of rows (unless the max number of pips is not a perfect root). ...
2
votes
0answers
99 views

Javascript: How to get the Object an object is prototype of

Javascript in the DOM has a peculiar characteristic. There's a different Object object that an object (by default) inherits per window. In order to find what kind of object is being sent to a ...
4
votes
2answers
558 views

Practices for organizing JavaScript AMD imports

Our company has been using newer versions of the Dojo framework, which have progressed to an AMD-based loader format. I'm currently trying to find logical ways to separate layer files, taking a module ...
43
votes
14answers
8k views

Is there any reason not to go directly from client-side Javascript to a database?

Possible Duplicate: Writing Web “server less” applications So, let's say I'm going to build a Stack Exchange clone and I decide to use something like CouchDB as my backend store. If I use ...
15
votes
0answers
723 views

Is there a reason for not using JavaScript for direct database connections on a web site? [duplicate]

I am thinking about using JavaScript for direct connection to our database server. I think I have solutions to all the possible problems about it. Security: Modern database management systems ...
1
vote
2answers
79 views

Software design for Client side form validation

So Im using the MEAN framework to build my web app. Like all other apps it requires a login & registration. My Approach so far has been: Every major function of my app has its own AngularJS ...
35
votes
5answers
11k views

How easy is it to hack JavaScript (in a browser)?

My question has to do with JavaScript security. Imagine an authentication system where you're using a JavaScript framework like Backbone or AngularJS, and you need secure endpoints. That's not a ...
7
votes
2answers
2k views

Any point in using ES6 Map when keys are all strings?

Plain object keys must be strings, whereas a Map can have keys of any type. But I have little use for this in practice. In nearly all cases, I find myself using strings as keys anyway. And presumably ...
30
votes
1answer
12k views

Why should I use Bower? [closed]

I can fully appreciate the benefits of a package manager like Python's pip, Node's npm, or Ruby Gems since they're doing much more than adding files to your applications path. Maybe I'm missing the ...
-1
votes
1answer
143 views

Showing a “context”-like menu in a span

Context of the question (some people believe it is useless to give such details, so feel free to skip them) It is about the MELT monitor (an alpha-stage GPLv3 free software, see also here). FWIW, I ...
2
votes
3answers
178 views

Angular JS style guide when declaring variables

I'm new to Angular JS and working on a project with "legacy" Angular JS code. The code is about a year or half a year old. I often see stuff like this: var _link; _link = "http://localhost"; Or: ...
3
votes
1answer
99 views

How to handle a client app that connects to a TCP server and sends/receives text data bidirectionally?

I've got a conceptual question (which is probably better posted here than on StackOverflow?). I want to develop a client application that maintains a persistent connection to a server, and exchanges ...
2
votes
1answer
187 views

Any reason to continue using plain strings in ES2015?

My current coding style is to use single-quoted strings as a default, and use backticked template literals whenever I need to concatenate a value into a string. But I'm now wondering what's the point ...
95
votes
4answers
14k views

Is there any reason to use the “var” keyword in ES6?

Babel's guide to ES6 says: let is the new var. Apparently the only difference is that var gets scoped to the current function, while let gets scoped to the current block. There are some good ...
2
votes
0answers
210 views

Authenticate Joomla user from an external app based on Node.js, Javascript and MongoDB

I have an iOS App which currently pulls in all the data from the MongoDB using a Node.js server. Currently my API / my node server handles all the data manipulation the iOS app/Swift only displays the ...
2
votes
0answers
64 views

Suggestions for Storing large collection of related words

I am trying to create a simple sentence generator that uses templates and a database of words. It will be a website where essentially a user could click a button to generate a sentence. For example: ...
1
vote
3answers
97 views

Is synchronously inspecting a promise an anti-pattern?

ES6 native promises do not allow you to synchronously check if they're resolved/pending/failed or to extract their value. I sometimes need this functionality and thus I have to code it manually. Is ...
1
vote
1answer
152 views

Is there any value in using a Promises library versus ES6 Promises?

I see a lot of NodeJS articles recommending the Bluebird library for promisifying your code and avoiding callback spaghetti. Is there any value in using such a library when using Node 4.2.4+ given ...
1
vote
3answers
158 views

How far should I validate user input in my own created API?

I got something here that bogs my mind a bit. Let's say I write me this API (in TS), check out some of these properties: export class MyAPI{ propertyThatShouldContainSuffix:Array<...
5
votes
2answers
159 views

Is Module Pattern in JavaScript is useful only for singleton creation?

Some articles (JavaScript Module Pattern In Depth, Mastering The Module Pattern) describe defining modules in JavaScript like in the snippet below (from Addy Osmani's "Learning JavaScript Design ...
120
votes
6answers
20k views

How much should I be using 'let' vs 'const' in ES6?

I've been writing a lot of ES6 code for io.js recently. There isn't much code in the wild to learn from, so I feel like I'm defining my own conventions as I go. My question is about when to use const ...
-1
votes
1answer
49 views

Javascript: Effect of passing entire object vs a property of the object as argument on performance

Does passing the entire object as argument rather than just a property of it, in javascript, effect performance? For example: <input type="button" onclick="getDetails(this)"/> vs <input ...
6
votes
3answers
1k views

Is break a code smell?

I'm asking in terms of a loop, obviously break is important in switch statements. Whether or not switch statements themselves are code smells is a separate issue. So consider the following use cases ...
7
votes
4answers
485 views

in dynamic language like javascript how do you know what the argument is?

In Java or Scala if I have an argument configuration: Conf, I can look for Conf class/trait/case class and see its construct so I know which arguments to pass. Recently I started dealing with ...
1
vote
4answers
191 views

How does this function returning a function work?

I'm having a hard time understanding exactly what is happening in the code here and how this script is changing other functions. This is taken from eloquentjavascript.net chapter 5 on higher order ...
1
vote
3answers
5k views

Advice for learning Javascript with prior knowledge of C++? [closed]

Recently I have become interested in learning Javascript for web development. I currently know HTML, CSS, and beginner/intermediate C++. I understand polymorphism, inheritance, and all of that fun ...
1
vote
1answer
330 views

JavaScript & AngularJs Modules Implementation technique and structure

So Im building an app and I'm trying to implement the structure of the app so that its robust and scalable in future. My app is mostly divided into JavaScript Modules (revealing pattern): // filter....
2
votes
4answers
936 views

Common header file for C++ and JavaScipt

I have an app that runs a C++ server backend and Javascript on the client. I would like to define certain strings once only, for both pieces of code. For example, I might have a CSS class "row-hover"...
0
votes
0answers
43 views

How to get dual UI for an ionic app?

I would like to get some suggestions for building a new app. This app has two faces/UI to it, buyer/seller. Users would have same account, and it would be seller and buyer. Its something similar to ...
1
vote
1answer
645 views

How to define dependent function in node js?

I have a nodejs project in which a sample.js include two function function A depends on function B's callback . // smaple.js Both function are included in the same file function B ( ...
2
votes
1answer
83 views

REST Standard for changing SPA Model after fetched from REST API

Let's imagine. I have following data from database. ====================================== id | Title | parentId ====================================== 100 Asia NULL ----------...
2
votes
1answer
91 views

Javascript and HTML decoupling

Based on the following snippet HTML <table id="example" class="display" cellspacing="0" width="100%"> <thead> <tr> <th>Name</th> <th>Position</th> &...
2
votes
1answer
354 views

Consuming REST services: client or server

I am working on a new project in which we are currently deciding which technologies and frameworks we will be using. The application will eventually be cross platform. Therefore, for the server side, ...
6
votes
2answers
186 views

Idiomatic way to write JavaScript class that maintains state and tells you when that state has changed

I am an experienced C++ developer but new to JavaScript. I want to write an ES6 JavaScript class that maintains state. How do I tell when state has changed? I can think of two ways to do this. One ...
-1
votes
1answer
83 views

Javascript Closures to Separate Class [closed]

PROBLEM: In Javascript I use closures to encapsulated methods inside a class. It helps building hierarchy inside and minimize amount of methods at root, but they become lengthy. RESEARCH: Applied to ...
-2
votes
1answer
257 views

Functional programming, and pushing item to array [closed]

I'm studying functional programming and I'm having some question concerning array population. Actually, I'm trying to rebuild the Array.prototype.map function, and here's what I've got: Array....
3
votes
1answer
61 views

A JavaScript IIFE prevents leaks to the global space as a closure? Is that the correct concept?

I see in the code or sometimes people talk about it, for some JavaScript code: (function() { var something; function someFunction() { // some code here } // do something }(...
4
votes
1answer
158 views

Filtering request and responses in RESTful MEAN stack

I have a very basic RESTful service written using the MEAN stack (MongoDb, Express.js, Angular.js, Node.js) and utilizing the Mongoose ODM. Product schema var productSchema = new mongoose.Schema({ ...