three 基础库
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.
 
 
 

71 lines
973 B

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 };