ostream chaining, output order

The behavior of your code is unspecified as per the C++ Standard. Explanation The following (I removed std::endl for simplicity) std::cout << “Hello, world!” << print( std::cout ); is equivalent to this: operator<<(operator<<(std::cout, “Hello, World!”), print(std::cout)); which is a function call, passing two arguments: First argument is : operator<<(std::cout, “Hello, World!”) Second argument is : … Read more

Javascript inheritance: call super-constructor or use prototype chain?

The answer to the real question is that you need to do both: Setting the prototype to an instance of the parent initializes the prototype chain (inheritance), this is done only once (since the prototype object is shared). Calling the parent’s constructor initializes the object itself, this is done with every instantiation (you can pass … Read more

How do I sequentially chain promises with angularjs $q?

Redgeoff, your own answer is the way I used to translate an array into a chained series of promises. The emergent de facto pattern is as follows : function doAsyncSeries(arr) { return arr.reduce(function (promise, item) { return promise.then(function(result) { return doSomethingAsync(result, item); }); }, $q.when(initialValue)); } //then var items = [‘x’, ‘y’, ‘z’]; doAsyncSeries(items).then(…); Notes: … Read more

How does basic object/function chaining work in javascript?

In JavaScript Functions are first class Objects. When you define a function, it is the constructor for that function object. In other words: var gmap = function() { this.add = function() { alert(‘add’); return this; } this.del = function() { alert(‘delete’); return this; } if (this instanceof gmap) { return this.gmap; } else { return … Read more