码迷,mamicode.com
首页 > 编程语言 > 详细

javascript-test1

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