AOP Compatibility

Brendan Eich brendan at mozilla.org
Wed Feb 20 14:20:07 PST 2008


On Feb 20, 2008, at 10:17 AM, Kris Zyp wrote:

> Is there any way this compatibility can be mitigated? I am assuming  
> there is
> no conceivable way to actually replace methods ad-hoc with arbitrary
> functions and retain sane typing and class expectations.

I'm not sure why you assume this. Latest RI downloaded from http:// 
ecmascript.org/ :

$ ./es4
ECMAScript Edition 4 RI v0.0M2 (Fri Feb 15 13:37:13 2008)
 >> save_getTime = Date.prototype.getTime
[function Function]
 >> Date.prototype.getTime = function advice() { intrinsic::print 
("before getTime"); let t = save_getTime(); intrinsic::print("after  
getTime"); return t; }
[function Function]
 >> d = new Date
Wed, 20 Feb 2008 22:15:18 GMT+0000
 >> d.getTime()
before getTime
after getTime
1203545718235
 >> save_Date_parse = Date.parse
[function Function]
 >> Date.parse = function more_advice() { intrinsic::print("yay!");  
return save_Date_parse.apply(this, arguments); }
[function Function]
 >> Date.parse(Date())
yay!
1203545824000

The builtins are backward-compatible as to class object and prototype  
mutation, including AOP hacks. The only proposed change for ES4,  
dependent on opt-in versioning, is making the constructor (now type)  
bindings immutable. Replacing Date in the global object is much less  
commonly done (but not unknown: Joel Spolsky's fogbugz does this, we  
learned via a crucial experiment in Firefox 3 beta 2).

/be



More information about the Es4-discuss mailing list