Javascript面向对象编程

对象的封装、继承、模块开发示例

//extends
var module = (function(window) {
'use strict';
    var Person = function(name, age) {
        this._name = name;
        this._age = age;
        console.log('Person is constructor executed...');
    };

    Person.prototype.getName = function() {
        return this._name;
    };

    Person.prototype.getAge = function() {
        return this._age;
    };

    // console.log(Person.prototype.constructor === Person); //true
    // console.log(Person.prototype.constructor.prototype === Person.prototype); //true
    // console.log(Person.prototype.constructor.prototype.constructor.prototype === Person.prototype); //true
    /********************Student extends Person*****************/

    var Student = function(name, age, score) {
        Person.call(this, name, age);  // 调用父类构造函数
        this._score = score;
        console.log('Student is constructor executed...');

    };


    Student.prototype = Object.create(Person.prototype); //new Person();
    Student.prototype.constructor = Student;    //其实并没有什么用处,历史遗留的产物,默认指向自己

    Student.prototype.getScore = function() {
        return this._score;
    }

    var stu = new Student('Rick', 23, 98);
/*
    console.log(stu.getName());
    console.log(stu.getAge());
    console.log(stu.getScore());*/

    return stu;

})(window);

console.log(module.getName());

JQuery插件模板
http://xhope.top/?p=499

参考网站:JavaScript 六种继承方式