-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProtoClass.min.js
11 lines (11 loc) · 2.92 KB
/
ProtoClass.min.js
1
2
3
4
5
6
7
8
9
10
11
/**
* ProtoClass.js – Standalone Prototype.js Class System
* By Seraf Dos Santos
*
* From Prototype.js
* Sam Stephenson
* Copyright (c) 2005-2010 Sam Stephenson
* Version 1.7
* MIT License
*/
var Enumerable=(function(){function toArray(){return this.map()}return{toArray:toArray}})();(function(){function extend(a,b){for(var c in b)a[c]=b[c];return a}function keys(a){var b=[];for(var c in a)b.push(c);return b}function isFunction(a){return typeof a==="function"}function isUndefined(a){return typeof a==="undefined"}extend(Object,{extend:extend,keys:keys,isFunction:isFunction,isUndefined:isUndefined})})();Object.extend(Function.prototype,(function(){var d=Array.prototype.slice;function update(a,b){var c=a.length,length=b.length;while(length--)a[c+length]=b[length];return a}function merge(a,b){a=d.call(a,0);return update(a,b)}function argumentNames(){var a=this.toString().match(/^[\s\(]*function[^(]*\(([^)]*)\)/)[1].replace(/\/\/.*?[\r\n]|\/\*(?:.|[\r\n])*?\*\//g,'').replace(/\s+/g,'').split(',');return a.length==1&&!a[0]?[]:a}function bind(b){if(arguments.length<2&&Object.isUndefined(arguments[0]))return this;var c=this,args=d.call(arguments,1);return function(){var a=merge(args,arguments);return c.apply(b,a)}}function wrap(b){var c=this;return function(){var a=update([c.bind(this)],arguments);return b.apply(this,a)}}return{argumentNames:argumentNames,bind:bind,wrap:wrap}})());function $A(a){if(!a)return[];if('toArray'in Object(a))return a.toArray();var b=a.length||0,results=new Array(b);while(b--)results[b]=a[b];return results}(function(){var a=Array.prototype,slice=a.slice,_each=a.forEach;function first(){return this[0]}Object.extend(a,Enumerable);Object.extend(a,{first:first,})})();var Prototype={emptyFunction:function(){}};var Class=(function(){function subclass(){};function create(){var a=null,properties=$A(arguments);if(Object.isFunction(properties[0]))a=properties.shift();function klass(){this.initialize.apply(this,arguments)}Object.extend(klass,Class.Methods);klass.superclass=a;klass.subclasses=[];if(a){subclass.prototype=a.prototype;klass.prototype=new subclass;a.subclasses.push(klass)}for(var i=0;i<properties.length;i++)klass.addMethods(properties[i]);if(!klass.prototype.initialize)klass.prototype.initialize=Prototype.emptyFunction;klass.prototype.constructor=klass;return klass}function addMethods(a){var b=this.superclass&&this.superclass.prototype;var c=Object.keys(a);if(!Object.keys({toString:true}).length){if(a.toString!=Object.prototype.toString)c.push("toString");if(a.valueOf!=Object.prototype.valueOf)c.push("valueOf")}for(var i=0,length=c.length;i<length;i++){var d=c[i],value=a[d];if(b&&Object.isFunction(value)&&value.argumentNames().first()=="$super"){var e=value;value=(function(m){return function(){return b[m].apply(this,arguments)}})(d).wrap(e);value.valueOf=e.valueOf.bind(e);value.toString=e.toString.bind(e)}this.prototype[d]=value}return this}return{create:create,Methods:{addMethods:addMethods}}})();