首页 > 其他 > 详细

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

时间:2016-06-02 18:14:06      阅读:140      评论:0      收藏:0      [点我收藏+]
<!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);
				}
				//拷贝所有方法到student
				student.prototype = new people();
				//获取子类实例方法对象
				var stSay = student.prototype.say;
				//重写父类方法
				student.prototype.say = function() {
					//调用基类方法,就用子类实例方法传this
					stSay.call(this);
					alert("subclass" + this._name);
				}
				//赋给全局属性,暴露接口
				window.student = student;
				
			}());//后面加“()”表示立即执行,外面套一层函数,是外部不能访问。
			
			var st = new student("lin");
			st.say();
		</script>
	</head>

	<body>
	</body>

</html>

  

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

原文:http://www.cnblogs.com/yqlog/p/5553638.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!