好的,这让我困惑了好几天!假设我有类似的东西:
var FooBar = function(args) {
this.annoy = typeof args == "boolean" ? args : false;
this.Foo();
}
FooBar.prototype.Foo = function() {
if (this.annoy)
window.alert("My name is Foo!")
else
window.console.log("My name is Foo!")
this.Bar()
}
FooBar.prototype.Bar = function() {
if (this.annoy)
window.alert("My name is Bar!")
else
window.console.log("My name is Bar!")
}
这工作正常。但是,如果Bar()被定义为另一个对象的属性,它又是FooBar's的属性prototype,有没有一种方法可以访问annoynewBar()而不必annoy作为参数传递给它?例如:
FooBar.prototype.evenDeeper = {
Bar: function() {
// I wish to access "annoy" here!
},
anotherOne: function() {
},
yetAnotherOne: 'value'
}
我可能错了,但我确信 inside Foo(),Bar()会被称为this.evenDeeper.Bar(),不是吗?此外,如果Bar()想要递归怎么办?Bar()只是将自己称为Bar()自身内部,或作为Foobar.evenDeeper.Bar()或this.Bar()或什么?
概括
- 如果在里面怎么
Bar()访问?annoyevenDeeper - 如何
Bar()在自身内指涉自身?
免责声明:我什至不alert()打算用s 来惹恼任何人!;)