怎么修改函数的内容

hhhct 2009-11-23 03:55:52
<script type="text/javascript">
function class(){
alert('a');
}
var a,b;
a=b=class;
//================================
做一些处理
//================================
a();//这里弹出b来
</script>
代码就是这了
不要修改a,a就是引用的class;
怎么做一些修改了
...全文
88 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
hhhct 2009-11-23
  • 打赏
  • 举报
回复
没什么意图啊
上次看到一个帖子
现在找不到了 我把大概意思写下来
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<body>
<script>
function A(a){
this.A =a;
this.AA = function(){
alert(this.A);
}
}

function B(b){
this.n = A
this.n('AAA');
delete this.n; //就是这个地方了
this.ooxx=function(){alert('ooxxooxxoo')}
}
new B().AA()
</script>
</body>
</html>

上面注释的地方啊
LZ问 为什么在这里要删除
LX其中一个人回答 因为 this.n是引用的A函数 怕this.n会改变A函数(这是cloudgamer的回答)
后面还有很多人也这么回答
但是没有一个例子
我自己测试又测试不出来
只好拿上来问问..........
yixianggao 2009-11-23
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 hhhct 的回复:]
ls
这样不能算拉
函数并没有发生变化
只是进行判断
[/Quote]
请 lz 先说明这样做的意图!

使用函数的目的在于封装处理过程代码,如果函数的内容改变了,那么就意味着函数的功能改变了,
那么就应该为重新定义一个新函数!

另,函数内容无法修改,只能动态覆盖函数名!
tan_kelin 2009-11-23
  • 打赏
  • 举报
回复
<html><head></head>
<body>
<iframe width="599" align="center" height="200" id="cwin" name="cwin" onload="Javascript:SetCwinHeight(this)" frameborder="0" scrolling="no" src="坐标网络排名__更多比较,更多选择.mht"></iframe>

</body></html>
<script>
function SetCwinHeight(obj)
{
var cwin=obj;
if (document.getElementById)
{
if (cwin && !window.opera)
{
if (cwin.contentDocument && cwin.contentDocument.body.offsetHeight)
cwin.height = cwin.contentDocument.body.offsetHeight;
else if(cwin.Document && cwin.Document.body.scrollHeight)
cwin.height = cwin.Document.body.scrollHeight;
}
}
}
</script>
hhhct 2009-11-23
  • 打赏
  • 举报
回复
ls
这样不能算拉
函数并没有发生变化
只是进行判断
yixianggao 2009-11-23
  • 打赏
  • 举报
回复
建议使用参数!或者重新定义函数!

另,class 是 JS 保留字,不要用做函数名!

L@_@K
function test(s){ 
if (s)
alert(s);
else
alert("a");
}
var a,b;
a=b=test;
a();
a("b");
licip 2009-11-23
  • 打赏
  • 举报
回复
那你得设计成类的形式,然后重定那个方法吧。
hhhct 2009-11-23
  • 打赏
  • 举报
回复
可以认为是把
class函数里面的内容变成
alert('b')
yixianggao 2009-11-23
  • 打赏
  • 举报
回复
lz 喝多了吧,说啥呢?!完全听不明白

87,907

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧