【发布时间】:2010-10-26 00:57:21
【问题描述】:
我想在 Javascript 中执行此操作:
function Z( f )
{
f();
}
function A()
{
this.b = function()
{
Z( function () { this.c() } );
}
this.c = function()
{
alert('hello world!');
}
}
var foo = new A();
foo.b();
可以这样实现:
function Z( f )
{
f();
}
function A()
{
var self = this;
this.b = function()
{
Z( function () { self.c() } );
}
this.c = function()
{
alert('hello world!');
}
}
var foo = new A();
foo.b();
有没有更好的办法?
【问题讨论】:
标签: javascript closures this