多重继承或访问对象外部的属性和方法
multi inherit or access the property and method outside the object
var ob = function(){
};
ob.prototype.func = function(){
};
var t = function(){
this.p=0;
this.function1(){
}
var a=new ob();
a.func=function(){//overrides the func
//hope to access this.p this.function1
}
};
是否可以使可以访问this.p this.function1
?欢迎您的评论
如果您想在
a.func
中访问它,则需要从内部保留对this
t
的引用。请尝试以下操作:
var t = function(){
var this_t = this; // Use this_t to access this.p and this.function1 inside a
this.p=0;
this.function1 = function(){
}
var a=new ob();
a.func = function(){//overrides the func
this_t.p = 1;
this_t.function1();
}
};
相关文章:
- 为什么NgModelController属性/方法以$开头
- 如何使用设置属性方法在jquery中更改css
- 全局向对象添加属性/方法
- AngularJS $http.delete 在“类型错误:无法分配给只读属性'方法'”中中断
- 添加属性/方法的明确最佳方法
- 扩展类时继承而不是覆盖属性/方法
- Javascript子类对象不保留基类的属性/方法
- 将模型属性方法发送到客户端 Sails Angular
- 错误:参数 4 的值无效.属性“方法”:意外属性
- 类型错误:无法读取 nodejs 应用程序中未定义的属性“方法”
- 属性/方法无法初始化indexedDB
- 在javascript中定义属性方法的适当模式;类”;
- 创建两个函数来计算对象属性/方法
- 当getElementById返回null时,取消对属性/方法的访问
- 自定义属性方法如何在Sails js中工作
- 通过js中的数组属性方法进行迭代
- 为什么要添加属性/方法到视图模型AFTER定义
- 在Angular中,在闭包中引用服务属性/方法最合适的方式是什么?
- 列出一个对象的所有属性/方法
- Javascript:添加属性方法问题