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
2answers
53 views

Anything wrong with direct evaluation of JSON if your own code created it?

Suppose I have a server-side variable containing JSON (named strJSON) that my own code created. In JavaScript I can consume it like this: var data = <%= strJSON %>; or use a JSON parsing ...
1
vote
2answers
58 views

Observer pattern: Prevent multiple firings on changed internal property

I have an object Foo that has 2 public properties: A and B. These properties can be changed from outside, as the application I'm working on is using a data-binding architecture. This is the ...
2
votes
1answer
97 views

Declaring JS Functions in Two Ways : What's the Benefit?

I've come across JS code in which I see functions being declared in two different styles: Method 1 function doSomething(){ alert('This is one way of declaring a function'); } Method 2 ...
1
vote
1answer
49 views

Assigning default values from environment variable in Node.js

When attempting to set default values for parameters that may exist in environment variables in JavaScript, I often see this pattern: var lag; try { lag = process.env.THROTTLE_LAG; } catch ( e ) ...
0
votes
0answers
15 views

Preserving Pre-formatted Multi-Line Strings in Node.js Scripts

There is a lot I don't like about PHP, but one thing I love is multi-line strings: $query = <<<EOT select field1 ,field2 ,field3 from tableName where field1 = 123 EOT; ...
9
votes
2answers
186 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 ...
-1
votes
0answers
51 views

Is it possible to manipulate mov files with js [on hold]

I'd like especially to know if it is possible to join two .mov-files using js. If there is no build-in-function, is it possible to manipulate the .mov-files "binary". In the end the .mov-file has a ...
-1
votes
0answers
30 views

How to create “fuzzy” material design type shadows on a canvas? [migrated]

I can't seem to find out how shadows are created in material design, or how css does it. Specifically, I am curious how, if given a canvas, one would create the 'blur' part, using algorithms. Below is ...
-5
votes
0answers
28 views

why alert pop up when window on loading, not by click button? [on hold]

<!DOCTYPE html> <html> <head> <meta charset="ISO-8859-1"> <title>Work with Numbers</title> <script src="labJS.js"> </script> </head> ...
0
votes
0answers
25 views

Better pattern with promise code [migrated]

I'm programing server side node for a huge project. And I'm thinking my brains out about the best programming pattern that will be suitable for fast modification and changes. Tell me what you think ...
2
votes
0answers
34 views

Correct Approach to Refactoring to Promises [migrated]

I am in the process of refactoring some complex code that uses callbacks to instead use promises. I am trying to figure out if my proposed approaches make sense. I did not think this was a good ...
2
votes
1answer
68 views

How to deal with server-side and client-side naming conventions that clash? [closed]

I have a project that uses the underscore naming convention for the MySQL database and PHP scripts but uses camelCase for the javascript application (a common scenario I'm sure). However, once JSON ...
2
votes
3answers
137 views

With only backend development experience, how do I go into frontend development (js, html, css)? [closed]

Currently I am interning at a company as a "full stack" developer (Application developer on the job title) and I realize that I am having difficulties coping with frontend tasks. This is especially ...
0
votes
1answer
121 views

Better pattern than large if/else if/else for checking conditionals [duplicate]

I've got a fairly large set of booleans I'm checking in javascript, and then using them to alter the state of a layout in my React app. The whole thing is unwieldy, difficult to read, inelegant, and ...
-1
votes
0answers
18 views

Read data from NFC chip to website [closed]

I need some way to read data from an NFC chip, and then use the data in a webapp (html/javascript/php). I need to attach a scanner to an ipad or computer, and then be able to retrieve some data from ...
3
votes
1answer
220 views

What is the most efficient / fastest way to keep a list in order?

I implemented Dijkstra's path finding algorithm in JavaScript and a big part of it involves storing the distances to nodes and fetching the smallest. The distances change often and the smallest is ...
-1
votes
0answers
35 views

What are HAXE alternatives? [closed]

I have a simple problem that I need to solve on multiple platforms. iOS, Android, jruby and browser. It mainly consists of basic arithmetics and key-value assignments. I would like to write the ...
2
votes
1answer
43 views

How Javascript Engines access/lookup property names?

How Javascript Engines access/lookup property names? what kind of associative array (data structure or search/lookup algorithm) did they use? (for V8, TraceMonkey, JSC, and Rhino) For example, in C++ ...
2
votes
1answer
69 views

The meaning of 'fully traversable namespaces' in JavaScript

During research into architecture of single page applications, I came across the following resource by Mikito Takada, written around 2013: http://singlepageappbook.com/ In his introduction he ...
0
votes
1answer
108 views

Does react.js make sense for a static content-driven site?

I'm pretty sold on the react.js model because it makes DOM manipulation so smooth and comprehensible. But I'm wondering how it could be leveraged for a site that's largely static with big blocks of ...
16
votes
1answer
680 views

When to use prototypical programming in JavaScript

I've spent a good bit of time developing simple widgets for projects in the following way: var project = project || {}; (function() { project.elements = { prop1: val1, prop2: val2 } ...
0
votes
0answers
19 views

modelling an ecosystem evolving on a landscape

I would like to understand a bit more the theory and the approaches available in modelling a population roaming across a landscape. Assume discrete time and space as simple as a discrete grid and a ...
0
votes
0answers
38 views

How to profile and compare two client-side approaches? [on hold]

I'm facing a project in which presumably large datasets will be interactively visualized client-side. These datasets' sizes vary, both in number of rows and number of columns. The visualizations and ...
-4
votes
0answers
21 views

PDF popup in Mozilla [migrated]

I have a PDF file generated through jsPDF. When the file opens in Mozilla, a popup windows appears as attached: I would like to put some meaningful description there instead of "blob". How can I do ...
4
votes
1answer
140 views

Does HTML 5 undercut the need for a full-featured Javascript framework? [closed]

We're redesigning a website. Right now it uses Dojo, a large (and complex) Javascript framework. One person insists that we need Dojo because of things like (random examples) client-side ...
5
votes
2answers
444 views

Where is the evidence for the performance of Node.js?

A lot of developers, especially ones who haven't used Node.js in production, seem to believe that Node.js is faster than other interpreted languages such as PHP, Python, and Ruby. These claims ...
0
votes
1answer
66 views

Should I prefer classes or singletons in JavaScript/Node?

This question applies especially to Node.js, but also to JavaScript in general. I started working on a simple web app in Node.js. I'm relatively new to Node and JavaScript, and come mainly from C# ...
2
votes
0answers
119 views

Deleting all cached page of the site [migrated]

Scenario Mobile and desktop version. I'm developing a website with a desktop and a mobile version: users can choose to switch version if they want to: javascript will save a cookie telling the ...
5
votes
3answers
221 views

Is prototypal inheritance inherently slower?

I see Javascript 6 will add traditional class based inheritance, and one argument I hear is that classes are inherently much faster than prototypes because they can be optimized away by the compiler ...
0
votes
1answer
80 views

Multi Room Chatroom Architecture [closed]

I'm building a multi room chatroom app, with some extra features that go beyond a few methods/calls. I'm wondering if I should: Manually create every method call on the clients and servers, which ...
-2
votes
0answers
10 views

javascript variables not defined in IE11 but defined in chrome [migrated]

There is a namepicker which is not functioning properly in ie11 but works fine in chrome. On inspection i found that the variables are undefined in IE11 but are defined in chrome. i used the alert ...
0
votes
0answers
21 views

Need to add websocket support to a single page that's running a wsgi service

Current setup. I have a legacy ERP system (Thoroughbred) and i then have several in house applications (CRM, WMS) and a website that interact with it via an xml server and straight ODBC connections. ...
1
vote
2answers
70 views

Literal strings vs. object properties in JavaScript

JavaScript libraries in the same space (UI widgets) use two different approaches for instantiating components: Literal strings to specify types, and inlining as much as possible, for example: var ...
1
vote
2answers
65 views

How to make scalable modules in a div element

I'm interested in creating web modules that are encapsulated by a div element in a manner that, by simply resizing the div, everything in that div scales to the dimensions of that div proportionately ...
0
votes
1answer
41 views

Measure and locate areas of similar value in an image

I saw this picture online and wanted to see if I could create an algorithm to give ordinary images an effect like this: http://justinlivi.net/wp-content/uploads/2011/01/Living_In_Digital.jpg My idea ...
2
votes
2answers
123 views

Why is the Document Object Model the view?

I was told by a Javascript programmer not to do DOM manipulation in model code. I also remember hearing a snazzy tune for a JS framework (I forget which one): "Get your models out of the DOM". This ...
0
votes
0answers
70 views

Reason why client-side JavaScript does not allow access to POST/PUT/etc contents

Is there any theoretical reason why client-side JavaScript could not be spec'd to allow for direct access to POST or PUT contents without need for a server language to write it into client-side ...
0
votes
1answer
50 views

Choose approaches for updating an object

Say I have a simple object created by from user input: var input = { url: 'http://example.com/', path: 'abc', user: 'adam' }; And I am to write function(s) that update url and path properties ...
1
vote
1answer
170 views

Using streams to connect programming languages

I'm trying to run a computation-heavy program that creates an image on a website. Is it possible to compute in C++ and have an output stream that connects to an input stream in Node.js to display an ...
0
votes
0answers
47 views

Login Tokens Remote DataServer for use in a Javascript/HTML-PHP environment

I've asked this question on stackoverflow, but i think this is a more appropriate place for it. I'm creating an app for iOS, Android and the Web. I created a separate Restful Data Service that is ...
0
votes
0answers
60 views

What's the Difference with these Knockout Viewmodel constructors?

When creating a viewmodel for Knockout, what's the difference here? I see these different implementations and I've tried a few and some don't work the same. //the most common example. function ...
2
votes
3answers
613 views

Why is it a good practice to keep Javascript code in separate files?

In web development we are commonly used to keep Javascript code in separate files, but sometimes we need this Javascript code to manipulate server side data locally. For example, making an Ajax Call ...
1
vote
1answer
172 views

What are the benefits of using new over closures

I've been programming in JS for over a year now, mainly in angularJS. And I can honestly say I've never made a function use prototypical inheritance. When ever i need a class like object that has ...
2
votes
2answers
350 views

should I test this public method

I have the following simple implementation: var VALIDATION_TYPES = { ERROR: 1, WARNING: 2 }; var validationRules = {}; this.addErrorRule = function (event, rule) { ...
13
votes
7answers
2k views

Is there a pattern for a more “natural” way of adding items to collections? [closed]

I think the most common way of adding something to a collection is to use some kind of Add method that a collection provides: class Item {} var items = new List<Item>(); items.Add(new ...
0
votes
0answers
26 views

Performance increase by only attach onblur handler inside of onfocus handler?

Given a web page with input fields, does it have a performance difference whether or not you assign the onblur handler inside of the onfocus handler like so: var inputFields = ...
0
votes
2answers
157 views

What is the best way to create dynamically a DOM?

I know that there are plenty answers to this question on stackoverflow, but I can´t find one that give me an answer that can help me to solve a question that came out after read a lot of Javascript, ...
-3
votes
2answers
103 views

How to convert a number into sum of numbers of specific length

I am trying to convert a number(x) into array of numbers so that their sum is equal to the number (x), but the array length should be equal to the given length. var x = 12 length 1: [12] = ...
2
votes
0answers
159 views

Is obtrusive javascript required to support a feature of angular.js?

I'll start by saying I'm just learning about Angular.js, and I was reading this article, which seems to advocate for obtrusive javascript as the right thing: ...
0
votes
1answer
90 views

How should I structure an application containing business logic and display? [duplicate]

I'm working on a simple board game that will run in the browser. I'm thinking how to structure the program and I'd like to hear your opinions. The program will consist of the user interface part (the ...