Object Cloning in Javascript

var phone1 = {
	make: 'Apple',
	model: 'Iphone 6',
	warranty: 12,
	extendWarranty: function(x){
		this.warranty += x;
    }
}
function clone(object){
	var c = function(){};
	c.prototype = object;
	return new c();
}
var phone2 = clone(phone1);

[vc_single_image image=”883″ img_size=”full”][vc_single_image image=”884″ img_size=”full”][vc_text_separator title=”OR”]

var phone1 = {myProp: 'Iphone'};
var phone2 = Object.assign({}, phone1)

[vc_single_image image=”891″ img_size=”full”]

Leave a Reply

Your email address will not be published. Required fields are marked *