Skip to content
This repository was archived by the owner on Jun 5, 2018. It is now read-only.

Commit a19a53e

Browse files
committed
add context.reset
1 parent 04ac504 commit a19a53e

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

lib/context.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ class Context {
1818
* 构造, 参数用来对 this 进行扩展.
1919
*/
2020
constructor(...extend) {
21-
this.rule = null;
22-
this.rules = [];
23-
this.stack = [];
2421
extend.forEach((ext) => {
2522
if (typeof ext === 'function')
2623
this[ext.name] = ext;
@@ -30,8 +27,19 @@ class Context {
3027
}
3128
}
3229
});
30+
this.reset();
3331
}
3432

33+
/**
34+
* 重置 .rule, .rules, .stack 为初始状态
35+
* @return {this}
36+
*/
37+
reset() {
38+
this.rule = null;
39+
this.rules = [];
40+
this.stack = [];
41+
return this;
42+
}
3543
/**
3644
* 遍历 x 回调 callback(val, key)
3745
* @param {object|array} x

0 commit comments

Comments
 (0)