-
Notifications
You must be signed in to change notification settings - Fork 0
/
prototype.Structure.js
33 lines (32 loc) · 1.02 KB
/
prototype.Structure.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*
* Module code goes here. Use 'module.exports' to export things:
* module.exports.thing = 'a thing';
*
* You can import it from another modules like this:
* var mod = require('prototype.Structure');
* mod.thing == 'a thing'; // true
*/
module.exports = function() {
// ADD MEMORY TO STRUCTURES
Object.defineProperty(Structure.prototype, 'memory', {
configurable: true,
get: function() {
if(_.isUndefined(Memory.structure)) {
Memory.structure = {};
}
if(!_.isObject(Memory.structure)) {
return undefined;
}
return Memory.structure[this.id] = Memory.structure[this.id] || undefined;
},
set: function(value) {
if(_.isUndefined(Memory.structure)) {
Memory.structure = {};
}
if(!_.isObject(Memory.structure)) {
throw new Error('Could not set structure memory');
}
Memory.structure[this.id] = value;
}
});
};