Luk*_*keS 4 javascript getter jslint this
我有一个带有get和set函数的简单全局对象.JSlint不喜欢我在get和set函数中使用"this",因为它违反了"use strict".我会用什么来替换"this",以免它违反"use strict"(即如何引用相同的东西"this"引用而不使用"this")?
function fnDirty() {
"use strict";
var bIsdirty = false;
this.get_bIsdirty = function() {return bIsdirty; };
this.set_bIsdirty = function(x) {bIsdirty = x; };
}
var GV_oDirty = new fnDirty();
Run Code Online (Sandbox Code Playgroud)
按照惯例,构造函数以大写字母开头.this如果您在构造函数中,JSLint将允许在严格模式下使用,但是您的字母以小写字母开头,因此它不会被识别为构造函数.
function FnDirty() {
//your code
}
Run Code Online (Sandbox Code Playgroud)