Last active
August 29, 2015 14:00
-
-
Save KJlmfe/11178189 to your computer and use it in GitHub Desktop.
JavaScript 单体模式-最基本结构的单体
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* JavaScript 单体模式 - 最基本结构的单体 */ | |
var Singleton = { | |
attribute1: "public attribute 1", | |
method1: function() { | |
console.log("This is public method1"); | |
// 不保险 若Singleton.method1作为一个事件监听器,那么this就会指向window | |
console.log(this.attribute1); | |
// 最保险 | |
console.log(Singleton.attribute1); | |
} | |
}; | |
// This is public method1 | |
// public attribute 1 | |
// public attribute 1 | |
Singleton.method1(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment