Created proper deep copy function

This commit is contained in:
Timothy Warren 2011-07-12 13:30:58 -04:00
parent 32db8c04c6
commit 1f7181d4be

37
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
@ -78,7 +77,39 @@
$_.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