Live data from Hacker News

JavaScript: Function Invocation Patterns

doctrina.org

51–52 of 52 posts

Re: JavaScript: Function Invocation Patterns

#51
post #47
post #41

Earlier quoted context omitted.

Not sure I understand your comment, given the link you gave. IMHO the return value of calling `Object()` without parameters is exactly what one would expect. Calling it w/ parameters is what I think causes surprising behavior var x = {a: 2} console.log(x === x) // true console.log(Object(x) === x) // true console.log(new Object(x) === x) // true For the `Object.call(x)` case, I'd expect it to return a new object (and…

[].slice.call(arguments) returning a new argument is fundamentally different because you would not want x.slice(1,2) to modify x in order to produce an appropriate sublist to return. Perhaps it's just me, but I expect a constructor to initialize "this" (optionally returning "this"), but not returning {};

Disagree. To illustrate:

    window.test = 2
    var b = Object.call(window) //this is the same as `var b = window.Object()` and therefore the same as `var b = Object()`
    assert(b.test == 2) //why should this be true?

Re: JavaScript: Function Invocation Patterns

#52
post #50
post #46

> Invoking a function suspends execution of the current function, passing controls and parameters to the invoked function. False. JS functions execute asynchronously, without suspending the execution of the current function.

Did I miss something here? Why was this downvoted?

Hi

I did not downvote your comment, but it is fundamentally incorrect. If your JavaScript program has been designed well, then asynchronisity by using an event driven model is the way to go. But that is very different to what I said about functions stopping the execution of the current function. This is true. For example

var func1 = function() { //Execute something here }

var func2 = function() { //Execute something here func1(); //Stop execution of this function, and rather execute func2 //Execute something here }

I hope the above explains this a bit better.

Post reply on HN