jQuery.Class

by Tenderfeel

JavaScript

var Class = (function() {
            function subclass() {}
            /* prototype.js  Function#argumentNames() */
            function argumentNames(f) {
                var names = f.toString().match(/^[\s\(]*function[^(]*\(([^)]*)\)/)[1]
                  .replace(/\/\/.*?[\r\n]|\/\*(?:.|[\r\n])*?\*\//g, '')
                  .replace(/\s+/g, '').split(',');
                return names.length == 1 && !names[0] ? [] : names;
              }
            function update(array, args) {
                var arrayLength = array.length, length = args.length;
                while (length--) array[arrayLength + length] = args[length];
                console.log(array)
                return array;
              }
            function wrap(child, wrapper) {
                var __method = child;
                return function() {
                  var a = update([$.proxy(__method, child)], arguments);
                  return wrapper.apply(child, a);
                }
              }
            return {
            create: function(parent) {
                   var ancestor;
                    function klass() {
                        var that = this;
                        try{ this.initialize.apply(this, arguments); }
                        catch(e){}
                    }
                    
                    klass.prototype.bind = function( e, f ){ $(this).bind(e,f); };
                    klass.prototype.trigger = function( e ){ $(this).trigger(e); };
                    
                    
                    var index = 0;
                    if(jQuery.isFunction(parent)) {
                        index = 1;
                        ancestor = parent && parent.prototype;
                        subclass.prototype = parent.prototype;
                        klass.prototype = new subclass;
                        klass.prototype._super = parent.prototype;
                    }
                    //Arguments[0] は  parent , parentがなければクラスのプロトタイプ用オブジェクト
...