当前位置:网站首页>^31 prototype interview questions

^31 prototype interview questions

2022-06-11 16:40:00 sanda_ nd

1、

 function A() {

        }
        A.prototype.n = 1
        var b = new A()
        A.prototype = { //A The prototype of is given a new object 
            n: 2,
            m: 3
        }
        var c = new A()
        console.log(b.n, b.m, c.n, c.m) //1 undefined 2 3

The relationship of each variable is shown in the figure :


2、

 function F(){}
        Object.prototype.a=function(){
            console.log('a.()')
        }
        Function.prototype.b=function(){
            console.log('b.()')
        }
        var f=new F()
        f.a()
        // f.b()  Report errors 
        F.a()
        F.b()

Just search according to the figure

 

Red : Implicitly deliver

Blue : Deliver... Explicitly


原网站

版权声明
本文为[sanda_ nd]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/162/202206111633429355.html