mardi 28 novembre 2017

What is reference and How to know reference of the object in javascript

What is the reference in object and how to see the reference allocated to the object in javascript.I used lodash _.clone() in an object and i made a example bellow

var  Obj = {id : 0, box: 0, ei : 0};
        var model = {id : 0,ob : [{c: 1, a: 0}],com: _.clone(Obj)};
        var old=_.clone(model)
        old.id=1;
        console.log(old.id===model.id); //false correct
        old.com.id=1;
        console.log(old.com.id===model.com.id);//true

while updating the old.id as 1 the model id has not updated,But while updating the old.com.id as 1 now the model.com.id has also updated why?




Aucun commentaire:

Enregistrer un commentaire