![]() | |
#1
| |||
| |||
|
#2
| ||||
| ||||
|
|
alert(foo.bar()); // this - ? 11.2.3 Function Calls 6. If Type(Result(1)) is Reference, Result(6) is GetBase(Result(1)). Otherwise, Result(6) is null. 7. If Result(6) is an activation object, Result(7) is null. Otherwise, Result(7) is the same as Result(6). 8. Call the [[Call]] method on Result(3), providing Result(7) as the this value and providing the list Result(2) as the argument values. |
|
alert((foo.bar)()); // this - ? |
|
alert((foo.bar = foo.bar)()); // this - ? |
|
10.2.3 Function Code * The caller provides the this value. If the this value provided by the caller is not an object (including the case where it is null), then the this value is the global object. |
#3
| |||
| |||
|
|
[...] I will be happy, if somebody explain better from me. [...] |
), it was very
#4
| |||
| |||
|
|
(foo.bar || foo.other)(); // global (foo.bar, foo.bar)(); // global (function () {})(); // global Yes, in previous post i forget very important part from specification. |
#5
| ||||||
| ||||||
|
|
On Nov 6, 2:26*pm, "Dmitry A. Soshnikov" <dmitry.soshni... (AT) gmail (DOT) com wrote: (foo.bar || foo.other)(); // global (foo.bar, foo.bar)(); // global (function () {})(); // global Yes, in previous post i forget very important part from specification. *11.2.1 Property Accessors and 11.1.2 Identifier Reference which explain: alert(foo.bar()); // this - ? |
|
alert((foo.bar)()); // this - ? |
|
Try it another test: function bar() { * * return this; } var foo = { * * bar: bar }; window.alert(foo.bar()); //this ? |
|
window.alert(Object(foo.bar)()); *//this ? |
|
window.alert((function(){return foo.bar;})()()); //this? |
|
with(foo) { * * window.alert(this.bar()); //this ? * * window.alert(bar()); //this ? [...] |
#6
| |||
| |||
|
#7
| |||
| |||
|
|
A little more practical exercise if no one minds: script type="text/javascript" *window.alert(window.navigator || 'undefined'); // alerts ? *var navigator = {'userAgent' : 'foobar'}; *window.alert(window.navigator || 'undefined'); // alerts ? /script 1,000 self-assigned bonus points if one names a popular browserwhere this code leads to a syntax error so never gets executed. |
#8
| |||
| |||
|
|
A little more practical exercise if no one minds: script type="text/javascript" window.alert(window.navigator || 'undefined'); // alerts ? var navigator = {'userAgent' : 'foobar'}; window.alert(window.navigator || 'undefined'); // alerts ? /script 1,000 self-assigned bonus points if one names a popularbrowser where this code leads to a syntax error so never gets executed. snip |
#9
| |||
| |||
|
|
The error is not a syntax error, it is a runtime error, which means that the code does get executed, up the point where the error is thrown (which is during variable instantiation for the global execution context). |
#10
| |||
| |||
|
|
[...] *var navigator; clause prevents the code execution. ![]() [...] |
![]() |
| Thread Tools | |
| Display Modes | |
| |