【发布时间】:2012-11-04 01:51:25
【问题描述】:
我正在使用面向对象为我的项目创建脚本文件,并且我还使用 jQuery 和 Datatables 等框架/小部件。
我在我的类上创建的公共属性无法从通过 jQuery 代码执行的函数的内部范围访问。
这是一个示例:
function MyClass() {
this.MyProperty = '';
}
MyClass.prototype.initialize = function() {
$(document).ready(function(){
alert(this.MyProperty); // MyProperty is undefined at this point
}
};
我该如何解决这个问题?这是拥有可以从类的每个成员访问的属性的正确方法吗?
【问题讨论】:
-
你想通过这一切达到什么目的?
标签: javascript jquery oop