On Sep 25, 2009, at 2:24 PM, Charles Jolley wrote:

But we can hear feedback, esp. on this list, about hardship adopting strict mode in early ES5 implementations. Mozilla's will be done shortly, and it sounds like WebKit's is coming along quickly too. Feedback based on two interoperable implementations in developers' hands before the ES5 spec is stamped done would have been best. But real-code/real-world feedback better late than never is welcome.

Once an implementation is out to play with you can be sure I will try to build SproutCore with ES5 in strict mode and report back!

But just to be clear, after all of the discussion here, it appears that the only way to implement a "call super" pattern in ES5 (without resorting to closures as Breton suggested) would be to use the following magic phrase everywhere I want to invoke super:

var IS_ES5_STRICT = /** detect ES5 strict mode somehow */

var IS_ES5_STRICT = typeof function(){return this;}() == "undefined";

or a variation (Mark Miller hat tip).


ClassB = ClassA.extend({
 foo: function method() {
(IS_ES5_STRICT ? method : arguments.callee).base.apply(this, arguments);
 }
});

But why wouldn't you use method always? Or callee, as Ollie suggested. Agree it's annoying to have to add six letters of cruft after the function keyword (with space separator) but once you do that, provided you dodge IE bugs, why do you need arguments.callee at all?


PS. Is there an official way to detect that I am running code in ES5 strict mode? I can't find it in the spec.

if (! function () {return this;}()) { /* in strict mode */ }

is IIRC a shorter way, relying on falsy-ness of undefined, to test.

/be

_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to