首页 > 编程语言 > 详细

javascript-test1

时间:2016-01-24 16:49:43      阅读:233      评论:0      收藏:0      [点我收藏+]
var AAA = function(name, age) {
	this.name = name ;
	this.age = age;
}

AAA.prototype.getName = function() {
	console.log(this.name);
}

AAA.prototype.getAge = function() {
	console.log(this.age);
}

var BBB = function(name, age, comments) {
	if(this instanceof BBB) {
		AAA.call(this, name, age);
		this.comments = comments;
	} else{
		return new BBB(name, age, comments);
	}
};

BBB.prototype = new AAA();
BBB.prototype.getComments = function() {
	console.log(this.comments);
}

var bbb = BBB(‘mhp‘, 17, ‘b‘);

console.dir(bbb);
bbb.getName();
bbb.getAge();// 17
bbb.getComments();// b
console.log(BBB.prototype instanceof AAA);

  

javascript-test1

原文:http://www.cnblogs.com/maduar/p/5155338.html

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