<script language="javascript">
function count(x,y,f){
var m,n,o,p;
m=x-y;
n=x+y;
o=x*y;
p=x/y;
if (f==1) return m;
if (f==2) return n;
if (f==3) return o;
if (f==4) return p;
}
</script>
<script>
var temp =count;
temp.prototype.m=count(5,2,1);
temp.prototype.n=count(5,2,2);
temp.prototype.o=count(5,2,3);
temp.prototype.p=count(5,2,4);
document.write(temp.prototype.m);
document.write(temp.prototype.n);
document.write(temp.prototype.o);
document.write(temp.prototype.p);
</script>
function count(x,y,f){
var m,n,o,p;
m=x-y;
n=x+y;
o=x*y;
p=x/y;
if (f==1) return m;
if (f==2) return n;
if (f==3) return o;
if (f==4) return p;
}
</script>
<script>
var temp =count;
temp.prototype.m=count(5,2,1);
temp.prototype.n=count(5,2,2);
temp.prototype.o=count(5,2,3);
temp.prototype.p=count(5,2,4);
document.write(temp.prototype.m);
document.write(temp.prototype.n);
document.write(temp.prototype.o);
document.write(temp.prototype.p);
</script>
prototype属性不是可以继承函数原型么?
通过if搭配return返回值,是不是太麻烦了?
请教像我的temp.prototype.m为什么不行呢?
function count(x,y){
var m,n,o,p;
var b=new Array();
m=x-y;
n=x+y;
o=x*y;
p=x/y;
b[0]=m;
b[1]=n;
b[2]=o;
b[3]=p;
return b;
}
</script>
<script>
var temp =count;
temp.prototype.b=new count(5,2);
document.write(temp.prototype.b[0]); //提示出错
document.write(temp.prototype.b[1]); //提示出错
document.write(temp.prototype.b[2]); //提示出错
document.write(temp.prototype.b[3]); //提示出错
</script>
<script language="javascript">
function count(x,y,f){
this.m=x-y;
this.n=x+y;
this.o=x*y;
this.p=x/y;
}var temp =new count(5,2,1);
alert(temp.m);
</script>
人家lbd8848(lbd)已经帮人家解决了问题,你偏要卖弄下。你以为人家lbd8848(lbd)不知道,没想到人家也能写出你要的代码。
不过这样或许楼主或许看不懂,
其实楼主需要知道的是return语句。
关键是做人,其次才是技术。
计算机技术无穷尽。你不可能样样精通!
学会做人!
这就是星星和三角的区别!
wfdmd(极品疯子),请教你一个问题,我哪里,何时卖弄了!??
非常感谢lbd8848(lbd)的答复和帮助.的却,按照他的方法的确可以解决问题.
但我就是搞不清楚prototype属性的具体用法,才有此一问.
你没有看到"请教"二字么?
难道在自己的帖子上想要弄懂自己不清楚的问题也有错么?
CSDN有这种规定么?
反观你的回复,除了对我人格的侮辱,有哪一点为这个帖子,为我,为以后搜索这个帖子的人提供了帮助.
如果你要灌水,可以去其他论坛.
如果你要释放你阴暗的心理,请考虑一下别人的感受!
最后
这个帖子不欢迎你!--------"高手"!
zhmt((……>!)) ,非常感谢!
那么请问,是不是在函数中,在变量和过程前加this.
然后在对象中就可以引用呢?
非常感谢!
this.m=x-y; //m为成员变量,加个this.就是成员变量
this.n=x+y;
this.o=x*y;
this.p=x/y; this.calculat=calculat; //成员函数
}function calculat()
{
alert(this.m);
}
var temp =new count(5,2,1);
temp.calculat();
alert(temp.m);
</script>
zhmt((……>!)) ,再次感谢你!
关于成员变量和成员函数.我有点模糊的概念了.
让我再看看书!
这个帖子我下周来结.
因为我不太明白prototype的具体含义和用法.
如果有哪位朋友能贴出点相关用法的代码,我将十分感激!
先谢谢你们,并祝周末愉快!
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script language="javascript">
function count(x,y){
this.m=x-y;
this.n=x+y;
this.o=x*y;
this.p=x/y;alert();
}
function cal(){
var value=new count(5,2);
txtm.value=value.m;
txtn.value=value.n;
txto.value=value.o;
txtp.value=value.p;
}
</script></head>
<body>
<p>
<input type="text" name="txtm"><input type="text" name="txtn">
<input type="text" name="txto"><input type="text" name="txtp">
<input type="button" value="cal()" onclick="cal()">
</p>
</body>
</html>
<script language="javascript">
function count(x,y){
var m,n,o,p;
m=x-y;
n=x+y;
o=x*y;
p=x/y;
return {m:m,n:n,o:o,p:p};
}
var temp = count(3,4);
document.write(temp.m);
document.write(temp.n);
document.write(temp.o);
document.write(temp.p);
</script>