Created proper deep copy function

This commit is contained in:
Timothy Warren 2011-07-12 13:30:58 -04:00
parent 32db8c04c6
commit 1f7181d4be
1 changed files with 36 additions and 5 deletions

41
kis.js
View File

@ -4,7 +4,6 @@
License Public Domain License Public Domain
Version 0.2.0 Version 0.2.0
*/ */
(function (){ (function (){
"use strict"; "use strict";
@ -18,7 +17,7 @@
return; return;
} }
var $_, $; var $_, $, dcopy;
/** /**
* String trim function polyfill * String trim function polyfill
@ -72,13 +71,45 @@
if(typeof sel === "undefined") if(typeof sel === "undefined")
{ {
sel = (typeof $_.el !== "undefined") sel = (typeof $_.el !== "undefined")
? $_.el ? $_.el
: window; : window;
} }
$_.el = sel; $_.el = sel;
return $_; return dcopy($_);
};
/**
* Deep copy/prototypical constructor function
*/
dcopy = function(obj)
{
var type, f;
if(obj == null)
{
return;
}
if(typeof Object.create !== "undefined")
{
return Object.create(obj);
}
var type = typeof obj;
if(type !== "object" && type !== "function")
{
return;
}
var f = function(){};
f.prototype = obj;
return new f();
}; };
//Set global variables //Set global variables