Esailija
  • Member for 10 years, 1 month
  • Last seen more than a month ago
  • Helsinki, Finland
Correct usage of Bluebird promise
2 votes

This question probably doesn't belong to programmers but var request = function() { return new Promise(function(resolve, reject) { ... resolve(data); ... reject(err); }...

View answer
Why are native ES6 promises slower and more memory-intensive than bluebird?
Accepted answer
282 votes

Bluebird author here. 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 ...

View answer
Are there any technical obstacles for implementing `function* ()` syntax
Accepted answer
1 votes

Because code that uses yield normally as variable would change its meaning: function test() { var yield = 3; return yield + 2 //in current javascript this means return 5 ...

View answer
What are the types of dynamically typed languages arrays?
Accepted answer
7 votes

Everything is like a void*, and yes it's more inefficient than values that are stored directly in the array. But for example in V8 an array can have three type modes: int, double, anything and only ...

View answer
Do sigils make source code easier to read?
Accepted answer
13 votes

The actual technical possibilites and limitations are nothing of the sort as are suggested throughout this thread. Let's clear out those first. Here's what $ is making possible in PHP: Variable ...

View answer
What should be the sense to use strict comparison to this specific string: 'final'
15 votes

Yes, for example typeof x == "string" is functionally exactly the same as typeof x === "string". However, x == " ", is not even remotely the same as x === " " since a string that is full of ...

View answer
Why do different java collections have different default capacity?
Accepted answer
17 votes

Short answer Because ArrayDeque capacity must be a power of two, and 16 is the smallest power of two that is at least 10. ArrayDeque needs to use a lot of % operations everywhere to wrap around a ...

View answer
Does modular programming affect computation time?
5 votes

Typically when you would otherwise have a large function and you split it into a lot of smaller ones, these smaller ones will be inlined because the only downside of inlining (repeating the same ...

View answer
What is the proper way to distinguish between keywords and identifiers?
Accepted answer
5 votes

If you notice in Ruby, you cannot call the method named like that directly, e.g. you cannot do begin() You can do obj.begin() Because there you can have grammar like: *Arguments* : "(" ")" *...

View answer
Using Power of 2 numbers to represent types
4 votes

If you use the bitwise or operator, you will get the value 5 print(TYPE_1 | TYPE_3) //5

View answer
Which is faster NSDictionaries or object properties?
4 votes

Object properties are generally at least an order of magnitude faster to access. Property access speed is also predictable whereas hash table access can take up to linear time. Accessing property can ...

View answer
If my team has low skill, should I lower the skill of my code?
34 votes

There seems to be a huge aversion to creating a function in JS. This aversion causes people try to be clever and use ridiculous tricks just to keep stuff in one line like a function call would have ...

View answer
The rationale behind Falsy values
2 votes

I use them to my advantage in Javascript all the time. In Javascript, the falsy values are undefined, null, false, NaN, 0 and "" It is just much easier to read: if( !str ) { } instead of if( str =...

View answer
Evaluating JSON from popular auto-suggests
Accepted answer
3 votes

JSONP is not technically a thing, it's actually just Javascript. So it's not JSON but Javascript object initializers. If you notice, Google's response does not run as Javascript code nor is it valid ...

View answer
How to modularize and package a client-side Javascript library today?
0 votes

Kinds of client-side libraries: Touches DOM Doesn't touch DOM With the first kind (UI widgets etc), you will typically assume jQuery is present. You can also write "DOM library agnostic" and have it ...

View answer
Why is the use of constructors discouraged when creating prototypes?
Accepted answer
5 votes

Because it's a function that doesn't need to be called. new is not that different from a regular function call in Javascript. A constructor can do more than simply set fields. For instance, if it ...

View answer
Does 'consider returning Null Object' apply to a DAO read method?
5 votes

A search suggests that there will be multiple results which is an easy case - always return a collection. If there are no results, then the collection will simply have no items. If there can be 0 or ...

View answer
Why does Java use so many middlemen?
2 votes

The level of control offered does no harm, you can always build abstraction on top of it that fits your requirements. It would be bad if no control or not enough control was offered at all. If you ...

View answer
Is $.proxy a code smell?
Accepted answer
5 votes

Well the alternatives to function binding are a lot worse, instead of a simple $.proxy call, the popular alternative is to type this every time var self = this; $().click( function(e) { self....

View answer
How does Javascript code become asynchronous when using callbacks?
Accepted answer
33 votes

It doesn't. Just taking a callback or passing a callback doesn't mean it's asynchronous. For example, the .forEach function takes a callback but is synchronous. var available = false; [1,2,3]....

View answer
Anonymous function performance - setTimeout
7 votes

The difference in Chrome, FF, IE10: UserAgent closure nonclosure static # Tests Chrome 25.0.1364 55,885,835 86,105,613 587,742,003 1 Firefox 19.0 31,856,561 67,442,...

View answer
What kind of JavaScript design pattern is this?
Accepted answer
1 votes

This is superfluous since you will only need a once instance of that object ever because it has no state. You can simply do var FormFieldsManager = { txtGradeName: function (txt) { ... ...

View answer
UTF-16 Pitfalls, Chinese
Accepted answer
12 votes

Why do you have this understanding? Both encodings [UTF-8 and UTF-16] can encode all unicode characters by the definition of them being unicode encodings. Anyway, UTF-8 is more optimal for storage ...

View answer
A Unicode sentinel value I can use?
16 votes

0xDC 0xDC Obviously invalid UTF-8 and ASCII Unpaired trail surrogate in lead position regardless of endianess in UTF-16. It doesn't get more invalid UTF-16 than that.

View answer
Security and code execution
2 votes

Basically you will be vulnerable to XSS - the element might as well be a script element or the paragraph element could have an onmouseover etc attributes to run a script. If you are not using ...

View answer
What is the proper jargon to refer to a variable wrapped inside a function closure?
Accepted answer
7 votes

According to wikipedia they're called "upvalues". A closure allows a function to access variables outside its immediate lexical scope. An upvalue is a free variable that has been bound (closed ...

View answer
What is jQuery and JavaScript's role in MVC?
Accepted answer
4 votes

Javascript is not related to the zend framework, or anything you use on the server. It runs in the browser. (Yes it could run anywhere but let's simplify) Let's say you have a desktop application ...

View answer