You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
973 B
72 lines
973 B
2 years ago
|
const NodeUtils = {
|
||
|
|
||
|
elements: [ 'x', 'y', 'z', 'w' ],
|
||
|
|
||
|
addShortcuts: function () {
|
||
|
|
||
|
function applyShortcut( proxy, property, subProperty ) {
|
||
|
|
||
|
if ( subProperty ) {
|
||
|
|
||
|
return {
|
||
|
|
||
|
get: function () {
|
||
|
|
||
|
return this[ proxy ][ property ][ subProperty ];
|
||
|
|
||
|
},
|
||
|
|
||
|
set: function ( val ) {
|
||
|
|
||
|
this[ proxy ][ property ][ subProperty ] = val;
|
||
|
|
||
|
}
|
||
|
|
||
|
};
|
||
|
|
||
|
} else {
|
||
|
|
||
|
return {
|
||
|
|
||
|
get: function () {
|
||
|
|
||
|
return this[ proxy ][ property ];
|
||
|
|
||
|
},
|
||
|
|
||
|
set: function ( val ) {
|
||
|
|
||
|
this[ proxy ][ property ] = val;
|
||
|
|
||
|
}
|
||
|
|
||
|
};
|
||
|
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
return function addShortcuts( proto, proxy, list ) {
|
||
|
|
||
|
const shortcuts = {};
|
||
|
|
||
|
for ( let i = 0; i < list.length; ++ i ) {
|
||
|
|
||
|
const data = list[ i ].split( '.' ),
|
||
|
property = data[ 0 ],
|
||
|
subProperty = data[ 1 ];
|
||
|
|
||
|
shortcuts[ property ] = applyShortcut( proxy, property, subProperty );
|
||
|
|
||
|
}
|
||
|
|
||
|
Object.defineProperties( proto, shortcuts );
|
||
|
|
||
|
};
|
||
|
|
||
|
}()
|
||
|
|
||
|
};
|
||
|
|
||
|
export { NodeUtils };
|