Code:
<script>
function Dog(){}
var dog = new Dog();
var dog1 = Object.create(dog);
// console.log(dog1._proto_);
console.log(Object.getPrototypeOf(dog1));
</script>
The instance dog1 is created using Object.create in the code, so the prototype of the instance dog1 should be dog. But two problems were encountered in the actual testing:
- console.log (dog1._proto_) outputs undefined. After Baidu, I saw a lot of saying that _ proto_ is a non-standard usage, which is not recommended until after es6, but the browser (I am using the latest version of chrome) should be parsable. Why output undefined?
2. So I switched to getPrototypeOf, but the output was not the prototype dog of dog1, but the constructor Dog.
confused about the above two points, solve