think-instance
Advanced tools
+1
-1
| { | ||
| "name": "think-instance", | ||
| "description": "add .getInstance method for class", | ||
| "version": "1.0.0", | ||
| "version": "1.0.1", | ||
| "author": { | ||
@@ -6,0 +6,0 @@ "name": "welefen", |
+4
-0
| # think-instance | ||
| [](https://travis-ci.org/thinkjs/think-instance) | ||
| [](https://coveralls.io/github/thinkjs/think-instance) | ||
| [](https://www.npmjs.com/package/think-instance) | ||
| ## Install | ||
@@ -4,0 +8,0 @@ |
+18
-0
@@ -109,3 +109,21 @@ import test from 'ava'; | ||
| test('get instance, set max & close 3', t => { | ||
| let close = 0; | ||
| let cls = class { | ||
| constructor(index){ | ||
| this.index = index; | ||
| } | ||
| close(){ | ||
| close += this.index; | ||
| } | ||
| } | ||
| cls = thinkInstance(cls, 1, 'close'); | ||
| const instance1 = cls.getInstance(2); | ||
| const instance2 = cls.getInstance(3); | ||
| const instance3 = cls.getInstance(4); | ||
| t.is(close, 5); | ||
| }); | ||
| test('get instance with multi args', t => { | ||
@@ -112,0 +130,0 @@ let cls = class { |
8254
9.97%165
10.74%24
20%