面向对象之类的封装与调用

来源:互联网 发布:淘宝品牌授权怎么弄啊 编辑:程序博客网 时间:2024/05/17 09:08
<!DOCTYPE html><html><head><meta charset="UTF-8"><title></title><script>(function() {function people(name) {this._name = name;}function student(name) {this._name = name;}//为原型对象添加say方法people.prototype.say = function() {alert("bassclass" + this._name);}//拷贝所有方法到studentstudent.prototype = new people();//获取子类实例方法对象var stSay = student.prototype.say;//重写父类方法student.prototype.say = function() {//调用基类方法,就用子类实例方法传thisstSay.call(this);alert("subclass" + this._name);}//赋给全局属性,暴露接口window.student = student;}());//后面加“()”表示立即执行,外面套一层函数,是外部不能访问。var st = new student("lin");st.say();</script></head><body></body></html>

  

0 0
原创粉丝点击