myvar = whatever;
namespace.myspace.Create = function () {
this.myvar = null;
this.MyFunction = function (val) {
this.myvar = val;
}
}
---
namespace.myspace.Create = function () {
var myvar = null;
this.MyFunction = function (val) {
this.myvar = val;
}
}
---
namespace.myspace.Create = function () {
myvar = null;
this.MyFunction = function (val) {
this.myvar = val;
}
}
var myObject = new namespace.myspace.Create();
查看上面的代码,尤其是 myvar 被定义为:
- this.myvar = null;
- var myvar = null;
- 我的变量=空;
它们的主要区别、范围和用途是什么?有什么陷阱或首选的做法吗?这些中的任何一个都完全错误并且不应该使用?