February 2009
2 posts
1 tag
JavaScript function definition inside a with()...
I came across yet another browser discrepancy with a rather obscure scenario: Accessing an object property from a function declaration within a with block for that object.
var obj = { a: 1 };
with (obj) {
function foo() {
return typeof a;
}
}
alert(foo()); // alerts "number" on Firefox, "undefined" on others
This exposes the object properties to the function scope only on...
1 tag
Browser discrepancies when calling toString() on a...
I had been working on parsing the source of JavaScript function instances when I realized that Function.prototype.toString() may return parts of the original comments in the source code, depending on the browser. I’ve done a quick test to capture the different behaviours of popular browsers.
Here’s my test script:
function/*post-keyword*/fn/*post-name*/()/*post-parens*/{
...