我知道javascript中没有静态变量这一说
例子:
var _FMath = function(){
this.eat = function(){
return "testtest";
};
this.SECOND = 1000;
}如上,我在类 _FMath定义了 SECOND 这个变量,并且这个类还有一些方法
我现在想用
FMath.SECOND 来直接调用这个方法,但是无法实现,所以我只能加一句
var FMath=new _FMath();
才可以!请问如何写才可以使 FMath.SECOND 直接可以使用?
例子:
var _FMath = function(){
this.eat = function(){
return "testtest";
};
this.SECOND = 1000;
}如上,我在类 _FMath定义了 SECOND 这个变量,并且这个类还有一些方法
我现在想用
FMath.SECOND 来直接调用这个方法,但是无法实现,所以我只能加一句
var FMath=new _FMath();
才可以!请问如何写才可以使 FMath.SECOND 直接可以使用?
var FMath = function(){
this.eat = function(){
return "testtest";
};
this.SECOND = 1000;
} 然后用 FMath.SECOND 可以直接取到1000
或者用其他方式定义,可以让 FMath.SECOND 可以使用
this.eat = function(){
return "testtest";
};
// this.SECOND = 1000;
} _FMath.SECOND = 1000;alert(_FMath.SECOND);
alert( new _FMath().SECOND );
这实际上是两个 SECOND 啊_FMath.SECOND = 500;
alert( new _FMath().SECOND );
alert( _FMath.SECOND );
var _FMath = function()
{
this.SECOND = _FMath["SECOND"];
this.eat = function()
{
return "testtest";
};
}
_FMath.SECOND = 500;
alert( new _FMath().SECOND );
alert( _FMath["SECOND"] ); //_FMath["SECOND"] 等同于2楼的 FMath.SECOND_FMath.SECOND = 300;
alert( new _FMath().SECOND );
//alert( _FMath["SECOND"] );</script>
SECOND:1000,
eat:function(){
return "testtest";
}
}
alert(_FMath.SECOND);