<分区>
是否可以让类在 JavaScript 中调用函数?
例如:
function Foo(){
this.alertCaller = alertCaller;
}
function Bar(){
this.alertCaller = alertCaller;
}
function alertCaller(){
alert(*calling object*);
}
调用 Foo().alertCaller() 时,我想输出类 Foo(),调用 Bar().alertCaller() 时,我想输出 Bar()。我有什么办法可以做到这一点吗?