我有2个Obj:我想知道如果他们是Singleton?JavaScript - 什么是单例类?
a。
var OBJ = function() {
}
OBJ.prototype = {
setName : function (name) {
this.name = name;
},
getName : function() {
return this.name;
}
}
b。
var OBJ = {
setName : function (name) {
this.name = name;
},
getName : function() {
return this.name;
}
}
可能重复?我不会继续编辑它。 – Blender 2013-02-26 07:13:52
@Blender我不知道我不能在代码中创建第二个块。我不知道为什么我看不到工具栏并预览它。 – Anar 2013-02-26 07:15:14
这将是有帮助的:http://www.hardcode.nl/subcategory_1/article_526-singleton-examples-in-javascript.htm – cclerville 2013-02-26 07:20:36