JavaScript prototype ÊôÐÔ
¶¨ÒåºÍÓ÷¨
prototype ÊôÐÔʹÄúÓÐÄÜÁ¦Ïò¶ÔÏóÌí¼ÓÊôÐԺͷ½·¨¡£
Óï·¨
object.prototype.name=value
ʵÀý
ÔÚ±¾ÀýÖУ¬ÎÒÃǽ«Õ¹Ê¾ÈçºÎʹÓà prototype ÊôÐÔÀ´Ïò¶ÔÏóÌí¼ÓÊôÐÔ£º
<script type="text/javascript">
function employee(name,job,born)
{
this.name=name;
this.job=job;
this.born=born;
}
var bill=new employee("Bill Gates","Engineer",1985);
employee.prototype.salary=null;
bill.salary=20000;
document.write(bill.salary);
</script>
Êä³ö£º
20000
TIY
- prototype
- ÔÚ±¾ÀýÖУ¬ÎÒÃǽ«Õ¹Ê¾ÈçºÎʹÓà prototype ÊôÐÔ¡£