原型测试题目

125 阅读1分钟

1.输出答案:

    var x = 1
    function MyClass () {
        this.x = 2
    } 
    MyClass.x = 3
    MyClass.prototype.x = 4
    MyClass.prototype.method = function () {
        console.log(this.x)
    }
    
    const prototype = MyClass.prototype
    const method = prototype.method
    
    new MyClass().method()
    prototype.method()
    method()
    
    // 2 4 1