1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | "use strict";
|
10 |
|
11 |
|
12 | function InvocationContext() {
|
13 | var s = this;
|
14 | s.init.apply(s, arguments);
|
15 | }
|
16 |
|
17 | InvocationContext.prototype = {
|
18 |
|
19 | init: function (values) {
|
20 | var s = this;
|
21 | s.set(values);
|
22 | },
|
23 | |
24 |
|
25 |
|
26 |
|
27 | clone: function () {
|
28 | var s = this;
|
29 | var Constructor = s.constructor;
|
30 | return new Constructor(s.get());
|
31 | },
|
32 | |
33 |
|
34 |
|
35 |
|
36 |
|
37 | set: function (data) {
|
38 | var s = this;
|
39 | Object.keys(data || {}).forEach(function (key) {
|
40 | s[key] = data[key];
|
41 | });
|
42 | return s;
|
43 | },
|
44 | |
45 |
|
46 |
|
47 |
|
48 | get: function () {
|
49 | var s = this;
|
50 | var data = {};
|
51 | Object.keys(s).forEach(function (key) {
|
52 | data[key] = s[key];
|
53 | });
|
54 | return data;
|
55 | },
|
56 | constructor: InvocationContext
|
57 | };
|
58 |
|
59 | /**
|
60 | * Define a context.
|
61 | */
|
62 | InvocationContext.define = function (values) {
|
63 | function Defined() {
|
64 | var s = this;
|
65 | s.init.apply(s, arguments);
|
66 | }
|
67 |
|
68 | Defined.prototype = new InvocationContext(values);
|
69 | Defined.prototype.constructor = Defined;
|
70 |
|
71 | return Defined;
|
72 | };
|
73 |
|
74 | module.exports = InvocationContext; |
\ | No newline at end of file |