NodeUtils.js 973 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. const NodeUtils = {
  2. elements: [ 'x', 'y', 'z', 'w' ],
  3. addShortcuts: function () {
  4. function applyShortcut( proxy, property, subProperty ) {
  5. if ( subProperty ) {
  6. return {
  7. get: function () {
  8. return this[ proxy ][ property ][ subProperty ];
  9. },
  10. set: function ( val ) {
  11. this[ proxy ][ property ][ subProperty ] = val;
  12. }
  13. };
  14. } else {
  15. return {
  16. get: function () {
  17. return this[ proxy ][ property ];
  18. },
  19. set: function ( val ) {
  20. this[ proxy ][ property ] = val;
  21. }
  22. };
  23. }
  24. }
  25. return function addShortcuts( proto, proxy, list ) {
  26. const shortcuts = {};
  27. for ( let i = 0; i < list.length; ++ i ) {
  28. const data = list[ i ].split( '.' ),
  29. property = data[ 0 ],
  30. subProperty = data[ 1 ];
  31. shortcuts[ property ] = applyShortcut( proxy, property, subProperty );
  32. }
  33. Object.defineProperties( proto, shortcuts );
  34. };
  35. }()
  36. };
  37. export { NodeUtils };