cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              (function(win,doc){

function UI(){}
function Common(){}
Common.prototype = Object.create(null,{
    'isArgay' : {
        value : function(obj){
            return /Arguments/.test(Object.prototype.toString.call(obj));
        }
    },
    'isArray' : {
        value : function(obj){
            return (obj instanceof Array);
        }
    },
    'copy' : {
        value : (function(){
            //var getValue;
            var isArgay = function(obj){
                    return /Arguments|Array/.test(Object.prototype.toString.call(obj));
            };
            var label = ['String', 'Number', 'Boolean', 'Function', 'RegExp', 'Date'];
            var reg   = [/String/, /Number/, /Boolean/, /Function/, /RegExp/, /Date/];
            var list  = [String  , Number  , Boolean  , Function  , RegExp  , Date  ];
            var doc = {
                'keys'  : null,
                'create'  : null,
                'trigger' : {
                    'object' : function(obj){
                    var root = (isArgay(obj) ? [] : {});
                        for(var key in obj){
                            root[key] = getValue(obj[key]);
                        }
                        return root;
                    },
                    'array' : function(obj){
                    var root = [];
                        for(var key in obj){
                            root.push(getValue(obj[key]));
                        }
                        return root;
                    },
                    'arguments' : function(obj){
                    var root = [];
                        for(var key in obj){
                            root.push(obj[key]);
                        }
                        return root;
                    },
                    'extend' : function(obj){
                    var root = [];
                        doc.create = doc.trigger.object;
                        for(var key in obj){
                            root.push(getValue(obj[key]));
                        }
                        return root;
                    }
                },
                set key(n){
                    switch(n){
                    case undefined :
                        n = 0;
                    break;
                    default :
                        n = this.keys.indexOf(n);
                        if(n < 0){ n = 0; }
                    }
                    this.create = this.trigger[this.keys[n]];
                },
                get key(){ return null; }
            };
            doc.keys = Object.keys(doc.trigger);
            var getValue = function(obj){
                switch(obj){
                case null      :
                case undefined : return obj;
                default        :
                    switch(obj.nodeType){
                    case undefined :
                    var name = null;
                        switch(obj.constructor.name){
                        case undefined :
                        //var item = new obj.constructor();
                        var item = obj.constructor.toString();
                            for(var i = 0; i < list.length; i = i + 1){
                                //if(item instanceof list[i]){
                                if(reg[i].test(item)){
                                    name = label[i];
                                    break;
                                }
                            }
                        break;
                        default :
                            name = obj.constructor.name;
                        }
                        switch(name){
                        case 'String'   :
                        case 'Number'   :
                        case 'Boolean'  :
                        case 'Function' : return obj;
                        case 'RegExp'   : return new obj.constructor(obj.source,obj.flags);
                        case 'Date'     : return new obj.constructor(obj.toString());
                        default         : return doc.create(obj);
                        }
                    break;
                    default    : return obj.cloneNode(true);
                    }
                }
            };
            return function(obj,prop){
                doc.key = prop;
                return doc.create(obj);
            };
        })()
    },
    'toArray' : {
        value :(function(self){
            var doc =  {
                owner : self,
                get     fnc (){ return this.owner.prototype; },
                get isArgay (){ return this.fnc.isArgay; },
                trigger : {
                    'extend' : function(obj){ return doc.fnc.copy(obj,'array');  },
                    'copy'   : function(obj){ return doc.fnc.copy(obj,'extend'); }
                 }
            };
            return function(obj){
                switch(arguments.length){
                case 0   : return doc.trigger;
                case 1   : return doc.fnc.copy(arguments[0],'arguments');
                default  : return doc.fnc.copy((doc.isArgay(arguments[0]) ? arguments[0] : arguments),'arguments');
                }
            };
        })(Common)
    },
    'constructor': { value: Common },
    'Name': { value: 'Common' }
});
UI.prototype = Object.create(Common.prototype,{
    'constructor': { value: UI },
    'Name': { value: 'UI' }
});

function getArg(){
    return arguments;
}

function f(){
var result = ui.toArray(arguments);
    result[2].aa = 100;
    result[3][1] = 200;
    console.log('arguments'    , arguments);
    console.log('arguments[2]' , arguments[2]);
    console.log('arguments[3]' , arguments[3]);
    console.log(' ');
    console.log('result'       , result);
    console.log('result[2]'    , result[2]);
    console.log('result[3]'    , result[3]);
    console.log(' ');
    console.log('arguments[2] == result[2]'          , arguments[2] == result[2]);
    console.log('arguments[3] == result[3]'          , arguments[3] == result[3]);
}

var ui = new UI();
var arr_old = [0,new Date(),/[a-z]/g,3,{'a':0,'b':{'c':'#fff','fnc':function(){console.log(this.c);}}},['a','b','c']];
var obj_old = {'a':100,'b':new Date(),'c':/[0-9]/g,'d':30,'e':{'a':0,'b':{'c':'#333','fnc':function(){console.log(this.c);}}},'f':['a','b','c',{'d':10,'e':20,'f':30},'d']};

var arr_new = ui.copy(arr_old);
var obj_new = ui.copy(obj_old);
    arr_new[0] = 10;
    obj_new.a = 10;

    console.log(0,'###### copy(obj) ######');
    console.log('[ Array ]');
    arr_new[4].b.c = '#000';
    arr_new[5][2] = 'z';
    console.log('arr_old',arr_old,arr_old[4].b,arr_old[5]);
    console.log('arr_new',arr_new,arr_new[4].b,arr_new[5]);
    arr_old[4].b.fnc();
    arr_new[4].b.fnc();
    console.log(' ');
    
    console.log('[ Object ]');
    obj_new.e.b.c = '#eee';
    obj_new.f[2] = 'z';
    obj_new.f[3].e = 200;
    console.log('obj_old',obj_old,obj_old.e.b,obj_old.f);
    console.log('obj_new',obj_new,obj_new.e.b,obj_new.f);
    obj_old.e.b.fnc();
    obj_new.e.b.fnc();
    console.log(' ');
    
    
    console.log(0,'###### toArray ######');
    console.log('arr_old',arr_old);
    console.log(0,'=== toArray(array) ===');
var to_arr = ui.toArray(arr_old);
    console.log('arr_new',to_arr);
    console.log('arr_old[4] == arr_new[4]',arr_old[4] == to_arr[4]);
    console.log('arr_old[5] == arr_new[5]',arr_old[5] == to_arr[5]);
    console.log(' ');
    
    console.log(0,'=== toArray(arguments) ===');
var arg = getArg(0,1,2,'a','b','c',{a:10});
    console.log('arguments',arg);
    console.log('toArray(arguments)',ui.toArray(arg));
    console.log('toArray.apply(null,arguments)',ui.toArray.apply(null,arg));
    //console.log('toArray(...arg)',ui.toArray(...arg));
    console.log('toArray(...arg?)',ui.toArray('a','b','c',100,200,300));
    f(0,1,{'aa':0},[0,1,2]);
    console.log('');
    console.log('');
    
    
    console.log(0,'=== toArray(object) ===');
    console.log('obj_old',obj_old);
    to_arr = ui.toArray(obj_old);
    console.log(to_arr);
    console.log('obj_old.e == to_arr[4]',obj_old.e == to_arr[4]);
    console.log(' ');
    
    console.log(0,'=== toArray().copy(object) ===');
var cp_arr = ui.toArray().copy(obj_old);
    console.log(cp_arr);
    console.log('obj_old.e == to_arr[4]',obj_old.e == cp_arr[4]);
    console.log(' ');
    
    console.log(0,'=== toArray().extend(object) ===');
var ex_arr = ui.toArray().extend(obj_old);
    console.log(ex_arr);
    console.log('obj_old.e == to_arr[4]',obj_old.e == ex_arr[4]);
    console.log(' ');
    
    console.log(0,'=== toArray().extend(array) ===');
    ex_arr = ui.toArray().extend(arr_old);
    console.log(ex_arr);
    console.log('obj_old.e == to_arr[4]',obj_old.e == ex_arr[4]);
    console.log(' ');
   
})(window,document);
            
          
!
999px
Loading ..................

Console