prototype 關鍵字可以為 JS原有對象 或者 自己創建的類 中添加方法或者屬性
也可以實現繼承
例子
<!DOCTYPE html PUBLIC "
<html xmlns="
<head>
<meta http
<title>JS中 prototype 關鍵字的使用</title>
</head>
<script>
<!
Number
return this+num;
}
function but
alert((
}
<!
function Car(cColor
this
this
}
Car
Car
alert("我跑了"+cLong+"公裡");
}
function but
var c = new Car("red"
c
alert(c
c
}
<!
function Rectangle(rWeight
this
this
if( typeof this
Rectangle
alert("test");
}
}
this
}
function but
var t = new Rectangle(
t
}
<!
function objectA(){
this
alert("我是A方法");
}
}
function objectB(){
this
alert("我是B方法");
}
}
objectB
function but
var t = new objectB();
t
t
}
</script>
<body>
<h
<hr />
<input id="but
<input id="but
<input id="but
<input id="but
</body>
</html>
From:http://tw.wingwit.com/Article/program/Java/JSP/201311/20470.html