Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
20
Task/Singleton/JavaScript/singleton.js
Normal file
20
Task/Singleton/JavaScript/singleton.js
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
function Singleton() {
|
||||
if(Singleton._instance) return Singleton._instance;
|
||||
this.set("");
|
||||
Singleton._instance = this;
|
||||
}
|
||||
|
||||
Singleton.prototype.set = function(msg) { this.msg = msg; }
|
||||
Singleton.prototype.append = function(msg) { this.msg += msg; }
|
||||
Singleton.prototype.get = function() { return this.msg; }
|
||||
|
||||
|
||||
var a = new Singleton();
|
||||
var b = new Singleton();
|
||||
var c = new Singleton();
|
||||
|
||||
a.set("Hello");
|
||||
b.append(" World");
|
||||
c.append("!!!");
|
||||
|
||||
document.write( (new Singleton()).get() );
|
||||
Loading…
Add table
Add a link
Reference in a new issue