var Book = function(name){
if(this.check(name)){
console.log("error");
throw new Error("name null");
}
this.name = name;
}
Book.prototype = {
check:function(name){
if(!name){
return true;
}
},
getName:function(){
return this.name;
}
}
var book = new Book("哈哈");
//output:哈哈 哈哈
console.log(book.name,book.getName());
var Book2 = function(name){
if(check(name)){
console.log("error");
throw new Error("name null");
}
name = name;
function check(name){
if(!name){
return true;
}
}
this.getName = function(){
return name;
}
}
Book2.prototype = {
display:function(){
//无法直接访问name
return "display:"+this.getName();
}
}
var book2 = new Book2("哈哈");
//output:undefined "哈哈" "display:哈哈"
console.log(book2.name,book2.getName(),book2.display());
var Book = function(name){
if(this.check(name)){
console.log("error");
throw new Error("name null");
}
this.name = name;
}
Book.prototype = {
check:function(name){
if(!name){
return true;
}
},
getName:function(){
return this.name;
}
}
function extend(subClz,superClz){
var F = function(){}
F.prototype = superClz.prototype;
subClz.prototype = new F();
subClz.prototype.constructor = subClz;
subClz.superClass = superClz.prototype;
if(superClz.prototype.constructor == Object.prototype.constructor){
superClz.prototype.constructor = superClz;
}
subClz.superClass = superClz.prototype;
if(superClz.prototype.constructor == Object.prototype.constructor){
superClz.prototype.constructor = superClz;
}
ArtBook.prototype.getName = functiion(){
return ArtBook.superClass.getName.call(this) + "!!!";
}
var ArtBook = function(name,price){
ArtBook.superClass.Constructor.call(this,name);
this.price = price;
}
extend(ArtBook,Book);
ArtBook.prototype.getPrice = function(){
return this.price;
}
ArtBook.prototype.getName = function(){
return ArtBook.superClass.getName.call(this)+"!!!";
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有