简体   繁体   中英

what is the difference between assigning one object to another object and returning object and assigning it to another object in javaScript?

so if we create two object

var dog = {
var name:"dog",
    makeSound: function(){
    alert("wow");
    }

}


var cate = {
var name:"cate",
    makeSound: function(){
    alert("meow");
    }

}

cate = dog;

now both cate and dog point to same object.

and if we do it like this

cate = object.create(dog);

what is the difference between the two is cate and dog point to same object now?

object.create

Creates a new object with the specified prototype object and properties.

MDN

Not with the same values !

While cate = dog; just tells cate to point to the same reference as dog .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM