首页 > 代码库 > JavaScript面向对象

JavaScript面向对象

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<script>
    (function () {
        var n = "me";
        function people(name){
            this.oo=name;
        }
        people.prototype.say= function () {
            alert("poe-hello"+this.oo+n)
        };

        window.people=people;
        return n;
    }());
    (function () {
        function student(name){
            this.oo=name;
        }
        student.prototype=new people();
        var sups=student.prototype.say;
        student.prototype.say= function () {
            sups.call(this);
            alert("stu-hello"+this.oo);

        }
        window.student=student;
    }());

    var s=new student("ii");
    s.say();
</script>
</body>
</html>

 

JavaScript面向对象