码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2016-06-02 18:16:32      阅读:141      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!