JavaScript笔试题练习与统计

JavaScript笔试题练习与统计

1.

  var a = 90;
        function Person() {
            var a = 100;
            this.x = 100;
            this.say = function () {
                console.log(this.x)
                console.log(this.y)
                fn(this)
            }
            function fn(arg) {
                console.log(arg)
                console.log(this)
                console.log(a)
            }
        }
        var a = { x: 90, y: 666, fm: function () { console.log(this) } }
        Person.prototype = a;
        var p1 = new Person()
        console.log(p1)
        p1.say()
        p1.fm()

这道题主要考的是作用域。在些这种题是就把自己当做计算机就行。
形实函运,记住一些优先级一步步运行下来即可。

2.

  function Parent(){
            this.a=1;
            this.b=[1,2,this.a];
            this.c={demo:5}
            this.show=function(){
                console.log(this.a,this.b,this.c.demo)
            }
        }
        function Child(){
            this.a=2;
            this.change=function(){
                this.b.push(this.a);
                this.a=this.b.length;
                this.c.demo=this.a++;
            }
        }
        Child.prototype=new Parent();
        var parent =new Parent();
        var child1=new Child();
        var child2=new Child();
        child1.a=11;
        child2.a=12;
        parent.show();
        child1.show();
        child2.show();
        child1.change();
        child2.change();
        parent.show();
        child1.show();
        child2.show();

一步一步向下运行即可,我就是计算机。

3.

    function fn(){
            rank = function(){console.log("盖伦")}
        console.log(this);
        return this
    }
    fn.rank =function(){
        console.log("赵信")
    }
    fn.prototype.rank=function(){
        console.log("典韦")
    }
    var rank=function(){
        console.log("项羽")
    }
    function rank(){
        console("琴女")
    }
    fn.rank()
    rank()
    fn().rank()
    rank()
    new fn.rank()//new (fn.rank))
    new fn().rank()//(new fn()).rank()
    new new fn().rank()//new(new fn()).rank()

把优先级搞懂就看能看懂,当你能把代码看成数学问题时说明你已经懂了。

4.

  function Person() { }

        Person.prototype = {
            greet: function () {
                console.log('Hello');
            }
        };

        var person = new Person();

        Person.prototype = {
            greet: function () {
                console.log('Hola');
            }
        };

        person.greet(); // 输出什么?

最后来个简单顺序问题。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值