prototype

Code
Shape = Class.create();
Shape.prototype
= {
initialize:
function(color){
this.color = color;
//alert('in initialize');
},
draw:
function(){
alert(
"in draw");
alert(
this.color);
}
}

Circle
= Class.create();
Circle.prototype
= Object.extend(new Shape(),{
initialize:
function(color,radius){
//alert('in Circle initialize');
this.color = color;
this.radius = radius;
},
drawCircle:
function(){
alert(
"in drawCircle");
alert(
"color:"+this.color);
alert(
"radius:"+this.radius);
}
})

var circle = new Circle("green", 10);
alert(circle
instanceof Shape);
alert(circle
instanceof Circle);

var shape = new Shape("red");
alert(shape
instanceof Shape);
alert(shape
instanceof Circle);

 

Code
function class1(){
}

class1.prototype
= {
m1 :
function() {
alert(
1);
}
}

function class2(){
}

class2.prototype
= class1.prototype;
class2.prototype.method
= function(){
alert(
2);
}

var obj1 = new class1();
var obj2 = new class2();

obj1.method();
obj2.method();

obj1.m1();
obj2.m1();

class2.prototype.m1
= function() {
alert(
3);
}

obj1.m1();
obj2.m1();

转载于:https://www.cnblogs.com/leavingme/archive/2008/10/30/1323174.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值