Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

make

  • Loading branch information...
commit 478a681a6eea4d2aa1be2517b685a9fe4e4afd7f 1 parent b953cb8
@fat fat authored
Showing with 38 additions and 50 deletions.
  1. +37 −49 klass.js
  2. +1 −1  klass.min.js
View
86 klass.js
@@ -6,76 +6,64 @@
*/
!function(context){
var fnTest = /xyz/.test(function (){xyz;}) ? /\bsupr\b/ : /.*/,
- noop = function(){}, proto = 'prototype',
+ noop = function(){},
+ proto = 'prototype',
isFn = function (o) {
return typeof o === 'function';
};
- function klass(o){
- var methods, _constructor = isFn(o) ? (methods = {}, o) : (methods = o, noop);
- return extend.call(_constructor, o, 1);
- };
+ function klass(o) {
+ return extend.call(typeof o == 'function' ? o : noop, o, 1);
+ }
+
+ function process(what, o, supr){
+ for (var k in o) {
+ if (o.hasOwnProperty(k)) {
+ what[k] = typeof o[k] == "function"
+ && typeof supr[proto][k] == "function"
+ && fnTest.test(o[k])
+ ? wrap(k, o[k], supr) : o[k];
+ }
+ }
+ }
+
+ function wrap(k, fn, supr) {
+ return function () {
+ var tmp = this.supr;
+ this.supr = supr[proto][k];
+ var ret = fn.apply(this, arguments);
+ this.supr = tmp;
+ return ret;
+ };
+ }
function extend(o, fromSub) {
- o = o || noop;
var supr = this,
- _methods,
- _constructor = isFn(o) ? (_methods = {}, o) : (_methods = o, this),
+ prototype = new noop(),
+ isFunction = typeof o == 'function',
+ _constructor = isFunction ? o : this,
+ _methods = isFunction ? {} : o,
fn = function () {
fromSub || isFn(o) && supr.apply(this, arguments);
_constructor.apply(this, arguments);
- },
- prototype = new noop();
-
- fn.methods = function (prop) {
- for (var name in prop) {
- prototype[name] = isFn(prop[name]) &&
- isFn(supr[proto][name]) && fnTest.test(prop[name]) ?
- (function(name, fn){
- return function() {
- this.supr = supr[proto][name];
- return fn.apply(this, arguments);
- };
- })(name, prop[name]) :
- prop[name];
- }
+ };
+ fn.methods = function (o) {
+ process(prototype, o, supr);
fn[proto] = prototype;
return this;
- }
+ };
fn.methods.call(fn, _methods).constructor = this;
fn.extend = arguments.callee;
- if (!fromSub) {
- for (var key in supr.prototype) {
- fn[proto][key] = supr.prototype[key];
- }
- }
-
- fn.statics = function (o) {
- for (var k in o) {
- o.hasOwnProperty(k) && (this[k] = o[k]);
- }
- return this;
- };
-
- function implement(name, f) {
- return function () {
- f.apply(this, arguments);
- return this;
- };
- }
-
- fn[proto].implement = function (ob) {
- for (var k in ob) {
- this[k] = implement(k, ob[k]);
- }
+ fn.prototype.implement = fn.statics = function (o) {
+ process(this, o, supr);
return this;
};
return fn;
- };
+ }
if (typeof module !== 'undefined' && module.exports) {
module.exports = klass;
View
2  klass.min.js
@@ -4,4 +4,4 @@
* Follow our software http://twitter.com/dedfat
* MIT License
*/
-!function(a){function g(a,f){function m(a,b){return function(){b.apply(this,arguments);return this}}a=a||c;var g=this,h,i=e(a)?(h={},a):(h=a,this),j=function(){f||e(a)&&g.apply(this,arguments),i.apply(this,arguments)},k=new c;j.methods=function(a){for(var c in a)k[c]=e(a[c])&&e(g[d][c])&&b.test(a[c])?function(a,b){return function(){this.supr=g[d][a];return b.apply(this,arguments)}}(c,a[c]):a[c];j[d]=k;return this},j.methods.call(j,h).constructor=this,j.extend=arguments.callee;if(!f)for(var l in g.prototype)j[d][l]=g.prototype[l];j.statics=function(a){for(var b in a)a.hasOwnProperty(b)&&(this[b]=a[b]);return this},j[d].implement=function(a){for(var b in a)this[b]=m(b,a[b]);return this};return j}function f(a){var b,d=e(a)?(b={},a):(b=a,c);return g.call(d,a,1)}var b=/xyz/.test(function(){xyz})?/\bsupr\b/:/.*/,c=function(){},d="prototype",e=function(a){return typeof a=="function"};typeof module!="undefined"&&module.exports?module.exports=f:a.klass=f}(this)
+!function(a){function i(a,b){var f=this,h=new c,i=typeof a=="function",j=i?a:this,k=i?{}:a,l=function(){b||e(a)&&f.apply(this,arguments),j.apply(this,arguments)};l.methods=function(a){g(h,a,f),l[d]=h;return this},l.methods.call(l,k).constructor=this,l.extend=arguments.callee,l.prototype.implement=l.statics=function(a){g(this,a,f);return this};return l}function h(a,b,c){return function(){var e=this.supr;this.supr=c[d][a];var f=b.apply(this,arguments);this.supr=e;return f}}function g(a,c,e){for(var f in c)c.hasOwnProperty(f)&&(a[f]=typeof c[f]=="function"&&typeof e[d][f]=="function"&&b.test(c[f])?h(f,c[f],e):c[f])}function f(a){return i.call(typeof a=="function"?a:c,a,1)}var b=/xyz/.test(function(){xyz})?/\bsupr\b/:/.*/,c=function(){},d="prototype",e=function(a){return typeof a=="function"};typeof module!="undefined"&&module.exports?module.exports=f:a.klass=f}(this)
Please sign in to comment.
Something went wrong with that request. Please try again.