Guest User

Untitled

a guest
Mar 19th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. var Class = (function () {
  2. initial = false;
  3.  
  4. // var _mix = function(target, source) {
  5. // for (var k in source) {
  6. // if (!target.hasOwnProperty(k)) {
  7. // target[k] = source[k];
  8. // }
  9. // }
  10. // return target;
  11. // }
  12.  
  13. var reg = /\b_super\b/;
  14.  
  15. var _extend = function(props) {
  16. var _super = this.prototype;
  17. initial = true;
  18. var prototype = new this();
  19. initial = false;
  20.  
  21. // var items = [].slice.call(arguments) || [];
  22. // var item
  23. // while(item = items.shift()) {
  24. // // 支持构造函数
  25. // _mix(prototype, item.prototype || item);
  26. // }
  27. for (var name in props) {
  28. prototype[name] = typeof props[name] === 'function' && typeof prototype[name] === 'function' && reg.test(props[name]) ?
  29. (function(fn, name) {
  30. return function() {
  31. var temp = this._super;
  32. this._super = _super[name];
  33. var ret = fn.apply(this, [].slice.call(arguments));
  34. this._super = temp;
  35. return ret;
  36. }
  37. })(props[name], name) : props[name];
  38. }
  39.  
  40. function SubClass() {
  41. if (!initial && this.init) {
  42. this.init.apply(this, arguments);
  43. }
  44. }
  45.  
  46. SubClass.prototype = prototype;
  47.  
  48. SubClass.extend = _extend;
  49.  
  50. return SubClass;
  51. }
  52.  
  53. function Class() {
  54.  
  55. }
  56.  
  57. Class.extend = _extend;
  58. return Class;
  59.  
  60. })();
Add Comment
Please, Sign In to add comment