JavaScript内存中的一些形状的读书笔记

原文地址:http://zoo.zhengcaiyun.cn/blog/article/code-shape

  1. undefined和null不同的原因
    undefined是栈空间中表示未定义含义的一块特殊的固定的内存区域
    null是堆内存空间中的具有固定内存地址且唯一存在的一个内置对象
    2.变量栈 堆 常量池
    函数定义缓存池
    3.组合继承的图解
function Animal(name) {
    this.name = name;
}

Animal.prototype.eat = function () {
    console.log('Animal eat');
};

function Dog(name) {
    Animal.apply(this, arguments);
}

var animal = new Animal();

Dog.prototype = animal;
Dog.prototype.constructor = Dog;
var dog = new Dog();
dog.eat();

console.log(Animal.prototype === animal.__proto__); // true

posted @ 2022-12-14 16:56  zeal666  阅读(15)  评论(0)    收藏  举报