注册 登录
编程论坛 JavaScript论坛

undefined 是什么原理

渐渐鱼 发布于 2018-06-23 15:09, 1879 次点击
运行挺正常的,但是最后在
alert(myCar.run());之后又弹出一个undefined的框??????????????


程序代码:
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
    </head>
    <body>
        <script>
        function Car(color,size)
        {
            this.color=color;
            this.size=size;
            this.run=run;
            this.voice=voice;
        }
        function run()
        {
            alert("I can run!");
        }
        function voice()
        {
            alert("I can voice!");
        }
        var myCar = new Car("red","middle");
        alert(myCar.color);
        alert(myCar.run());
        alert(myCar.voice());
        </script>
    </body>
    </html>
2 回复
#2
林月儿2018-06-23 17:56
程序代码:
function Car(color,size)
        {
            this.color=color;
            this.size=size;
            this.run=run();
            this.voice=voice();
        }
        function run()
        {
            return "I can run!";
        }
        function voice()
        {
            return "I can voice!";
        }
        var myCar = new Car("red","middle");
        alert(myCar.color);
        alert(myCar.run);
        alert(myCar.voice);
#3
渐渐鱼2018-06-24 15:42
回复 2楼 林月儿
谢谢^_^
1