Skip to content Skip to sidebar Skip to footer

Inconsistent Behaviour Of "this" In Javascript Strict Mode

Update For clarity: @FelixKing: Yes, I expected this to still be undefined when calling window.foo(), and here's why: since, in JavaScript: function foo() { console.log('I am a

Solution 1:

I'm not sure if I'm reading your question right, but it seems as if you are having trouble with the fact that func.apply(context, arguments) can take context as a parameter which will be then be reffered by this inside the function.

I would argue that passing the context is necessary and JavaScript couldn't work properly without it.

Off the top of my head, since there is no super the only way to use inheritance properly is to use something like BaseClass.prototype.baseFunction.apply(this, arguments).

Removing that functionality would create a language that is very different from JavaScript today and that is not what strict mode is about.

Post a Comment for "Inconsistent Behaviour Of "this" In Javascript Strict Mode"