我只是想更深入地了解JavaScript。
我创建了一个名为gameData
的“类”,我只需要一个实例,不需要构造函数或实例化。
因此我这样创建它...
var gameData = new function () {
//May need this later
this.init = function () {
};
this.storageAvailable = function () {
if (typeof (Storage) !== "undefined") {
return true;
}
else {
return false;
}
};
}
意识到 'new' 关键字不能实例化类,并使其像 C# 中的静态类一样可用。
我想得对吗?就像静态一样?
new function()
(https://dev59.com/ZHE95IYBdhLWcg3wheRR)。 - Bergi