Tag Info

Hot answers tagged

43

I did this, and I recommend that you don't. What I did was write all the business logic in Lua, and stored that Lua script in a database. When my application started up it would load and execute the script. That way I could update the business logic of my application without distributing a new binary. I invariably found that I always needed to update the ...


39

My reply here is not javascript-specific. As a rule of thumb in any language that lets me do so in a semi-easy way I'd say always use const/final/readonly/whatever it is called in your language whenever possible. The reason is simple, it's much easier to reason about code when it is dead obvious what can change and what cannot change. And in addition to ...


35

Piping dynamic data into an interpreter of your implementation language is usually a bad idea, since it escalates the potential for data corruption into a potential for malicious application takeover. In other words, you are going out of your way to create a code injection vulnerability. Your problem can be better solved by a rules engine or maybe a ...


6

In ECMAScript 5, yield is a strict-mode "Future Reserved Word": 7.6.1.2 Future Reserved Words The following words are used as keywords in proposed extensions and are therefore reserved to allow for the possibility of future adoption of those extensions. ... class enum extends super const export import The following tokens are also ...


6

There is no theoretical limit to how deep JSON objects can be nested, but there usually is a practical limit based on the decoder being used. For example, PHP's json_decode() has a default limit of 512 levels, though it can be adjusted. Read the documentation for the code using the JSON to determine the max depth. If your JSON is actually hitting depth ...


6

Bluebird author here. The accepted answer is wrong. V8 promises implementation is written in JavaScript not C. All JavaScript (including V8's own) is compiled to native code. Additionally user written JavaScript is optimized, if possible (and worth it), before compiled to native code. Promises implementation is something that would not benefit much or at ...


5

I would say it depends of the language. In a strongly typed language like Java, pasing a Map<String, Object> means that you risk using the wrong type for a parameter. That said, I have seen this been used in frameworks like ExtJS and, for some tasks that require lots of parameters (like initialization, configuration) it is worth it. It actually helps, ...


5

It depends on what kind of I/O you're after. I think that table is primarily looking at system calls, and the stdin/stdout interface to a console windows or terminal. System calls simply don't exist in Javascript, and there's no stdin/stdout-style console window either, so I assume that's why it's not listed (though you can make a case for node.js here). ...


5

The usual solution in this situation is to have a selected class that defines the style of a button that represents the current page - i.e. a different color for the bottom border. When the current page changes, use JS to remove the selected class from all buttons and add it to the one that was just clicked.


4

webSocket is implemented in browsers (not in the underlying OS). It is built on top of TCP/IP which comes from the OS. You can see which versions of which browsers support webSockets here:http://caniuse.com/#feat=websockets


4

For a few reasons: It often forces you to choose longer names, where a shorter one would be more clear and concise within a limited scope. For example, filter versus MyModuleNameFilter. The process of "taking the responsibility to make sure you have very good names and they will never overlap" gets increasingly difficult the larger your code base gets ...


3

I would not have the database contain code. But you can do something similar by having the database contain function names and then using reflection to call them. When you add a new condition, you have to add it to your code and your database, but you can combine conditions and parameters that get passed to them to create quite complex evaluations. In ...


3

Because global variables have global scope, they are visible, and mutable, by anything that runs on the page. That introduces implicit coupling between all code running on the page; everything could interact with everything. That runs contrary to the concept of encapsulation. If your code, and variables are local in scope, it's easier to reason about thing; ...


2

This question mainly stems from worrying about maintenance so I will make an assumption that you are going to have many of these state-dependent functions. I would recommend having a layer in between your client and the function that it is calling which is state dependent. Then let this layer handle the state management. This will do two things for you: ...


2

XACML is the solution you are really looking for. It is a type of rules engine that is focused on access control only. XACML, a standard defined by OASIS, defines three parts: an architecture a policy language (which is really what you want) a request / response scheme (how you ask for an authorization decision). The architecture is as follows: the ...


2

V8 and other language implementations using similar techniques are just-in-time compilers. They generate code, and that generated code is speculatively optimized (with checks to fall back to slower, more general code if the specialization turns out to be invalid). So when generating code, the JIT compiler often has a good guess at what the hidden class of an ...


2

JavaScript does not have any I/O at all, and thus the question whether or not it is "failsafe" doesn't make sense.


2

Javascript is indeed a fail-safe language, since it also raises exceptions in case of an error (like Java or Python). However, the specific language is not included in this list, because this list refers to fail-safe programming languages taking into account the occasions of errors in I/O operations and system calls. Javascript has been a client-side ...


2

Most of the big JavaScript frameworks tend to include the following features: Ajax API Event manager/listeners Promises Class system DOM widgets Templating My recommendation is to study and implement each of these concepts. As you work through them, you'll find that most of them tie together on some fundamental level. Ajax and Promises work well ...


1

This question probably doesn't belong to programmers but var request = function() { return new Promise(function(resolve, reject) { ... resolve(data); ... reject(err); } }; Is of course much slower than var request = promisify(function(callback) { ... callback(null, data); ... callback(err); }); However, ...


1

Assuming the language is dynamically typed, I can see two different ways this could be handled without knowing at compile time if a call is async. One approach would be to assume every call could be async. However, this would be incredibly inefficient and produce a lot of extra code. This is essentially what you are doing in option 2. Another option is to ...


1

Stick to a pure Javascript and HTML template solution to package that all up into a single minified .js file. Use sprites for fewer images. These may have their own auxiliary benefits (eg. saves bandwidth by minifying JS), but I wouldn't make any changes like this purely for reasons of making my deployment more convenient. You haven't ...


1

JavaScript does not support parameter defaults for function declarations. function foo(x) { console.log(x); } foo(); // outputs undefined You would have to add extra code per parameter to set the default value. function foo(x) { if(typeof x === 'undefined') { x = 0; } console.log(x); } foo(); // outputs 0 This becomes a pain when there ...


1

One way to fight the large amount of parameters is a builder pattern + fluid interface. Consider: widget = makeWidget(100, 200) .withSize(384, 256) .withColors(foreground, background) .withBorder('solid', 'black', 1) .withDialogButtons('OK', 'Cancel', 'Help') This approach groups related sets of parameters so that each ...


1

"I will take the responsibility to make sure...". Many unexpected babies arrive that way. But seriously: keeping names unique with a growing code base that may include other libraries is a difficult and risky process that is ultimately doomed to failure. your very own code will start to get really hard to read and follow when you set and read these ...


1

"Never put variables in global scope" is a best practice because it makes those variables brittle. A typical web page or especially a typical web application is likely to contain many different scripts from multiple sources, and as careful as you may be to track your own global variables, everyone else whose scripts you're referencing may not be playing ...


1

The key is that this is being used in a JIT which produces specialized code. Let's say that have a function something like this: function add_points(a, b) { return new Point(a.x + b.x, a.y + b.y); } V8 will actually generate different versions of this function, for different possible arguments that you pass in. For example, it would generate a version ...



Only top voted, non community-wiki answers of a minimum length are eligible