【发布时间】:2015-09-18 10:01:14
【问题描述】:
假设我需要声明一些 private static 成员以在一些 public static 方法中使用它。 .
// ***** Variant I *****
function supports() {
var impl = document.implementation; // private, non-static
this.SVG = function () { // public, non-static
return impl.hasFeature("http://www.w3.org/TR/SVG11/feature#Image", "1.1");
};
}
// ***** Variant II *****
function supports() { }
supports.prototype.impl = document.implementation; // public, non-static
supports.SVG = function () { // public, static
return impl.hasFeature("http://www.w3.org/TR/SVG11/feature#Image", "1.1");
};
我知道使用“静态”OOP 概念的 JavaScript 存在一些困难,所以我的问题是:
我可以在“对象”的“声明主体”中声明 public static 方法inside(如上面的“变体 I”) )?
【问题讨论】:
-
supports.prototype.impl = ...- 公共非静态(成员) -
@hindmost:感谢指正!我相应地修复了评论
标签: javascript oop static-methods