How do i make a copy of an object? Javascript

Posted by acidzombie24 on Stack Overflow See other posts from Stack Overflow or by acidzombie24
Published on 2010-04-20T07:00:29Z Indexed on 2010/04/20 7:03 UTC
Read the original article Hit count: 176

Filed under:

I have a class in json format. I would like to make two instance. Right now (its pretty obvious why) when i 'make' two objects i really have 2 vars pointing to one. (b.blah = 'z' will make a.blah=='z')

How do i make a copy of an object?

var template = {
    blah: 0,
    init: function (storageObj) {
        blah = storageObj;
        return this; //problem here
    },
    func2: function (tagElement) {
    },
}

a = template.init($('form [name=data]').eq(0));
b = template.init($('form [name=data2]').eq(0));

© Stack Overflow or respective owner

Related posts about JavaScript