在javascript对象的属性中将其作为基本对象的上下文
我想知道我需要做什么才能在java脚本对象的子属性中维护一种类型的(var self=this)耦合。例如,如果我有以下对象:在javascript对象的属性中将其作为基本对象的上下文,javascript,object,Javascript,Object,我想知道我需要做什么才能在java脚本对象的子属性中维护一种类型的(var self=this)耦合。例如,如果我有以下对象: var t = { helpers: { getName: function(){ //how do i preserve this or get the mbase object instance here... //so i can for example do the following:
var t = {
helpers: {
getName: function(){
//how do i preserve this or get the mbase object instance here...
//so i can for example do the following:
var self = this;//this is now helpers object, but how to get to base object?
return self.nickName + "...";
},
getTime: function(){
}
},
nickName: 'test'
}
根据我目前的理解,如果该引用是对象的属性,那么它在对象中的引用将直接传递到函数中。因为这个场景是两个对象,所以当我引用(var self=this)时,它是基对象还是“helpers”对象?如果是,我如何到达obj.helpers.get昵称()中的基对象属性,例如“nickNam”
提前谢谢。
t.昵称
应该知道,我已经把这件事复杂化了。谢谢。t.nickName
应该知道,我把这件事复杂化了。谢谢