Tag Archives: source-in

ECMA V5时代后,我们能玩的东西

当V5正式降临的时候,我们能玩的就多了。看看吧:

Posted in Browser, 中文 | Also tagged , | Leave a comment

“resend in Self”, on JavaScript ECMA-v5

Self中resend是调用“基类方法”的原语,它会把当前接收到的消息原样发送给其原型(parent*)。在ECMA-v5时代,我们终于可以做出这个伟大的东西了。 ECMA V5定义了一个期待已久的方法:Object.getPrototypeOf,它可以无视型别信息得到某对象的原型([[prototype]]),基于此,我们可以构造出一个resend:(请用Chrome 5、IE9预览第三版测试) obj.resend = function() { var pof = Object.getPrototypeOf; var has = function() {……} // hasOwnProperty的封装 var make = function(obj, old) { return function(name, args) { var step = pof(obj), r; while (step && !has(step, name)) step = pof(step); if (!step) throw new Error(‘Unable to resend: method missing’); var foundMethod = step[name]; var backup = arguments.callee; this.resend [...]

Posted in Browser, 中文 | Also tagged , , , , | Leave a comment