首页 > 为什么会弹两下,最后一个居然还有个undefined

为什么会弹两下,最后一个居然还有个undefined

function Person(name){
        this.name=name;
        this.age=function(age){alert(this.name+'现在'+age+'岁了!');};
        this.action={
            'eat':function(something){alert(name+'正在吃'+something)},
            'look':function(something){alert(name+'正在看'+something)},
            'run':function(){alert(this.name+'能跑!');}
        };
    }

    var person=new Person('小明');
    
    alert(person.age(10));


上面这段代码只弹了一下

不过 'run':function(){alert(this.name+'能跑!');}
this.name 应该是拿不到的

【热门文章】
【热门文章】