Skip to content

t2ym/thin-wrap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

npm Bower

thin-wrap

Thin Class Wrapper (experimental)

function loggerForwarder(prop, f, args, self, newTarget) { 
  console.log('wrap: ' + (newTarget ? 'new ' : '') + f.name + ' is called for ', (self && self.name ? self.name : self), 'with arguments', args);
  return newTarget ? Reflect.construct(f, args) : f.apply(self, args);
}
wrap(XMLHttpRequest, loggerForwarder);
wrap(EventTarget, loggerForwarder);

Install

Browsers

  bower install --save thin-wrap

NodeJS

  npm install --save thin-wrap

Import

Browsers

<script src="path/to/bower_components/thin-wrap/wrap.js"></script>

NodeJS

const wrap = require('thin-wrap/wrap.js');

API

TBD

Advantages

  • Small overheads (Significantly faster than ES6 Proxy)
  • this is unique and identical for each instance

Known Limitations

Architectural Limitations

  • Class !== Class.prototype.constructor
  • new Class() is not trackable
  • new Class.prototype.constructor() or new (wrap(Class))() is trackable
  • Properties without setter/getter are not trackable

Current Design Limitations

  • Inherited properties are not tracked
  • Generation of setter/getter for properties are not implemented

License

BSD-2-Clause