javascript的函数对象使用

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        function createStudent(name,age,sex,score) {
            var student = new Object();
            student.name = name;
            student.age = age;
            student.sex = sex;
            student.score = score;

            student.sayHi = function ()
            {
                //this的含意,和PHP一样,在对象函数中使用函数外属性需要用上this
                console.log("大家好,我是"+this.name);
            };
            //返回对象,
            return student;
        }

        var s1 = createStudent("张三",18,"男",18);
            s1.sayHi();
    </script>
</head>
<body>

</body>
</html>


评论

大侠名号:   验证码: 点击我更换图片  

修远兮

在这里记录每一点自己需要的知识

添加创始人微信,一起交流心得

推荐文章RECOMMEND