Skip to content

Commit 62fbdec

Browse files
committed
Create singelton.js
1 parent 355812c commit 62fbdec

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

singelton.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// The Singleton Pattern limits the number of instances of a particular object to just one.
2+
// http://www.dofactory.com/javascript/singleton-design-pattern
3+
4+
//The instances in clouser.
5+
6+
function Singelton() {
7+
var instance = this;
8+
9+
Singelton = function() {
10+
return instance
11+
};
12+
13+
Singelton.prototype = this;
14+
15+
instance = new Singelton();
16+
17+
instance.constructor = Singelton;
18+
19+
return instance;
20+
}
21+
22+
var x = new Singelton();
23+
x.someProp = true;
24+
var y = new Singelton();
25+
y.someProp = false;
26+
x.someProp // false

0 commit comments

Comments
 (0)