项目原始demo,不改动
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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 
 
 

27 line
674 B

  1. module.exports = ProxyHandler;
  2. var ProxyHandler = function(cbs){
  3. this._cbs = cbs || {};
  4. };
  5. var EVENTS = require("./").EVENTS;
  6. Object.keys(EVENTS).forEach(function(name){
  7. if(EVENTS[name] === 0){
  8. name = "on" + name;
  9. ProxyHandler.prototype[name] = function(){
  10. if(this._cbs[name]) this._cbs[name]();
  11. };
  12. } else if(EVENTS[name] === 1){
  13. name = "on" + name;
  14. ProxyHandler.prototype[name] = function(a){
  15. if(this._cbs[name]) this._cbs[name](a);
  16. };
  17. } else if(EVENTS[name] === 2){
  18. name = "on" + name;
  19. ProxyHandler.prototype[name] = function(a, b){
  20. if(this._cbs[name]) this._cbs[name](a, b);
  21. };
  22. } else {
  23. throw Error("wrong number of arguments");
  24. }
  25. });