函数原型prototype的用处? 为什么需要函数的原型?我见一些JS的代码,大体如下function a(){}a.prototype={}究竟prototype有什么用? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 看一下这里你就知道了:http://blog.csdn.net/xxd851116/archive/2009/04/02/4043336.aspx <script type="text/javascript"><!-- function fnHandler1(name, age){ this.name = name; this.age = age; } fnHandler1.prototype.Alert = function(){ alert(this.name + "---" + this.age); } var fn1 = new fnHandler1("Tom", "23"); fn1.Alert(); function fnHandler2(name, age){ this.name = name; this.age = age; this.Alert = function(){ alert(this.name + "---" + this.age); } } var fn2 = new fnHandler2("Jack", "24"); fn2.Alert(); /* 两个函数比较下就可以看出fn1的好处就是 共性的Alert方法不需要每次new都要实例化一次 *///--></script> 怎样删除指定div后的所有内容 outerHTML 在IE和Firefox里没用怎么办 select 求各位老手指教!如果学习javascript onsubmit事件在firefox中不识别 window.clipboardData.getData('Text')问题 关于从动态表格里取值的问题 为何document.all.inputname.value无法更改<input>的value值? 我碰到了很有用,很奇怪的问题。 高手指点,有点困难,在客户端自建对象的问题 如何使javascript代码运行时,在浏览器不屏蔽 对象的理解
<script type="text/javascript">
<!--
function fnHandler1(name, age){
this.name = name;
this.age = age;
} fnHandler1.prototype.Alert = function(){
alert(this.name + "---" + this.age);
} var fn1 = new fnHandler1("Tom", "23");
fn1.Alert(); function fnHandler2(name, age){
this.name = name;
this.age = age;
this.Alert = function(){
alert(this.name + "---" + this.age);
}
} var fn2 = new fnHandler2("Jack", "24");
fn2.Alert();
/*
两个函数比较下就可以看出fn1的好处就是
共性的Alert方法不需要每次new都要实例化一次
*///-->
</script>