diff options
| author | ruki <waruqi@gmail.com> | 2018-11-08 00:38:48 +0800 |
|---|---|---|
| committer | ruki <waruqi@gmail.com> | 2018-11-07 21:53:09 +0800 |
| commit | 26105034da4fcce7ac883c899d781f016559310d (patch) | |
| tree | c459a5dc4e3aa0972d9919033ece511ce76dd129 /node_modules/utila/lib/classic.js | |
| parent | 2c77f00f1a7ecb6c8192f9c16d3b2001b254a107 (diff) | |
| download | xmake-docs-26105034da4fcce7ac883c899d781f016559310d.tar.gz xmake-docs-26105034da4fcce7ac883c899d781f016559310d.zip | |
switch to vuepress
Diffstat (limited to 'node_modules/utila/lib/classic.js')
| -rw-r--r-- | node_modules/utila/lib/classic.js | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/node_modules/utila/lib/classic.js b/node_modules/utila/lib/classic.js new file mode 100644 index 00000000..a77bd328 --- /dev/null +++ b/node_modules/utila/lib/classic.js @@ -0,0 +1,86 @@ +// Generated by CoffeeScript 1.6.3 +var classic, + __slice = [].slice; + +module.exports = classic = {}; + +classic.implement = function() { + var classProto, classReference, desc, member, mixin, mixins, _i, _j, _len; + mixins = 2 <= arguments.length ? __slice.call(arguments, 0, _i = arguments.length - 1) : (_i = 0, []), classReference = arguments[_i++]; + for (_j = 0, _len = mixins.length; _j < _len; _j++) { + mixin = mixins[_j]; + classProto = classReference.prototype; + for (member in mixin.prototype) { + if (!Object.getOwnPropertyDescriptor(classProto, member)) { + desc = Object.getOwnPropertyDescriptor(mixin.prototype, member); + Object.defineProperty(classProto, member, desc); + } + } + } + return classReference; +}; + +classic.mix = function() { + var classProto, classReference, desc, member, mixin, mixins, _i, _j, _len; + mixins = 2 <= arguments.length ? __slice.call(arguments, 0, _i = arguments.length - 1) : (_i = 0, []), classReference = arguments[_i++]; + classProto = classReference.prototype; + classReference.__mixinCloners = []; + classReference.__applyClonersFor = function(instance, args) { + var cloner, _j, _len, _ref; + if (args == null) { + args = null; + } + _ref = classReference.__mixinCloners; + for (_j = 0, _len = _ref.length; _j < _len; _j++) { + cloner = _ref[_j]; + cloner.apply(instance, args); + } + }; + classReference.__mixinInitializers = []; + classReference.__initMixinsFor = function(instance, args) { + var initializer, _j, _len, _ref; + if (args == null) { + args = null; + } + _ref = classReference.__mixinInitializers; + for (_j = 0, _len = _ref.length; _j < _len; _j++) { + initializer = _ref[_j]; + initializer.apply(instance, args); + } + }; + classReference.__mixinQuitters = []; + classReference.__applyQuittersFor = function(instance, args) { + var quitter, _j, _len, _ref; + if (args == null) { + args = null; + } + _ref = classReference.__mixinQuitters; + for (_j = 0, _len = _ref.length; _j < _len; _j++) { + quitter = _ref[_j]; + quitter.apply(instance, args); + } + }; + for (_j = 0, _len = mixins.length; _j < _len; _j++) { + mixin = mixins[_j]; + if (!(mixin.constructor instanceof Function)) { + throw Error("Mixin should be a function"); + } + for (member in mixin.prototype) { + if (member.substr(0, 11) === '__initMixin') { + classReference.__mixinInitializers.push(mixin.prototype[member]); + continue; + } else if (member.substr(0, 11) === '__clonerFor') { + classReference.__mixinCloners.push(mixin.prototype[member]); + continue; + } else if (member.substr(0, 12) === '__quitterFor') { + classReference.__mixinQuitters.push(mixin.prototype[member]); + continue; + } + if (!Object.getOwnPropertyDescriptor(classProto, member)) { + desc = Object.getOwnPropertyDescriptor(mixin.prototype, member); + Object.defineProperty(classProto, member, desc); + } + } + } + return classReference; +}; |
