一个简单而好玩的问题,今天我考别人的
有函数a 函数b
<%
function b()
Response.write("hello world!")
end function
function a(str)
//这句来执行b函数,请问怎么写?
end function
a "b"
%>
很简单的一个问题,呵呵,祝大家愉快
问题点数:300、回复次数:99Top
1 楼dh20156(风之石)回复于 2006-05-27 21:26:24 得分 34
call eval(str)
^_^Top
2 楼liuxiaoyi666(MSMVP 小猪妹荣誉马甲之八卦兔子)回复于 2006-05-27 21:33:42 得分 0
呵呵,不只这一种方法....Top
3 楼jspadmin(阿笨狗http://www.pifoo.com域名空间专卖cn20、com50元)回复于 2006-05-27 21:41:19 得分 0
???Top
4 楼slawdan(select 大便 from 粪池 where 蛆数<10)回复于 2006-05-27 21:45:02 得分 0
execute strTop
5 楼dh20156(风之石)回复于 2006-05-27 21:50:17 得分 34
直接 call bTop
6 楼jspadmin(阿笨狗http://www.pifoo.com域名空间专卖cn20、com50元)回复于 2006-05-27 21:55:34 得分 0
直接 call b
-------------------
会出错的,缺少参数Top
7 楼liuxiaoyi666(MSMVP 小猪妹荣誉马甲之八卦兔子)回复于 2006-05-27 21:56:04 得分 0
execute str
我说的是这个....
嘿嘿,如果是js呢,你知道有啥不同么?Top
8 楼wolfhero(小炉子)回复于 2006-05-27 21:56:54 得分 0
call bTop
9 楼slawdan(select 大便 from 粪池 where 蛆数<10)回复于 2006-05-27 21:57:57 得分 0
js 有execute 么?
不会是 execute(str)吧?~~~
汗一下~~Top
10 楼liuxiaoyi666(MSMVP 小猪妹荣誉马甲之八卦兔子)回复于 2006-05-27 22:02:34 得分 0
<script>
function b(){
alert("hello world!");
}
function a(str){
//这句来执行b函数,请问怎么写?
}
a("b");
</script>Top
11 楼liuxiaoyi666(MSMVP 小猪妹荣誉马甲之八卦兔子)回复于 2006-05-27 22:03:03 得分 0
呵呵,跟vbs略有不同....Top
12 楼slawdan(select 大便 from 粪池 where 蛆数<10)回复于 2006-05-27 22:04:21 得分 0
exec?Top
13 楼mingxuan3000(铭轩)回复于 2006-05-27 22:07:21 得分 0
难题呀 ..Top
14 楼mingxuan3000(铭轩)回复于 2006-05-27 22:07:54 得分 0
b()?Top
15 楼liuxiaoyi666(MSMVP 小猪妹荣誉马甲之八卦兔子)回复于 2006-05-27 22:09:14 得分 0
倒,当然不是这个意思了....呵呵,其实是用eval函数的在js里,不过跟vbs在用法上有所不同Top
16 楼mingxuan3000(铭轩)回复于 2006-05-27 22:10:38 得分 0
调用函数要用eval?Top
17 楼liuxiaoyi666(MSMVP 小猪妹荣誉马甲之八卦兔子)回复于 2006-05-27 22:13:23 得分 0
忘了说限定条件是不许直接调用函数的.....Top
18 楼slawdan(select 大便 from 粪池 where 蛆数<10)回复于 2006-05-27 22:13:42 得分 0
兔子讲课吧Top
19 楼dh20156(风之石)回复于 2006-05-27 22:14:14 得分 0
<script>
function b(){
alert("hello world!");
}
function a(str){
eval(str).call(0);
}
a("b");
</script>Top
20 楼samoonm()回复于 2006-05-27 22:15:10 得分 0
JS:
---------------------
eval(str + "()" );
---------------------Top
21 楼mingxuan3000(铭轩)回复于 2006-05-27 22:16:12 得分 0
eval("b()")Top
22 楼liuxiaoyi666(MSMVP 小猪妹荣誉马甲之八卦兔子)回复于 2006-05-27 22:16:47 得分 0
to 风之石
漂亮!!!!!代码比我写的漂亮
<script>
function b(){
alert("hello world!");
}
function a(str){
eval(str+"()");
}
a("b");
</script>Top
23 楼mingxuan3000(铭轩)回复于 2006-05-27 22:18:31 得分 0
调用b和 str没关系吧Top
24 楼mingxuan3000(铭轩)回复于 2006-05-27 22:19:44 得分 0
明白了,str就是b的字符串Top
25 楼mingxuan3000(铭轩)回复于 2006-05-27 22:21:06 得分 0
这题目没说清楚Top
26 楼dh20156(风之石)回复于 2006-05-27 22:22:03 得分 34
献丑哦 ^_^Top
27 楼liuxiaoyi666(MSMVP 小猪妹荣誉马甲之八卦兔子)回复于 2006-05-27 22:22:35 得分 0
to mingxuan3000(铭轩)
不好意思,可能是我出题写得不明确吧
其实问的应该是通过 str调用b 8好意思Top
28 楼mingxuan3000(铭轩)回复于 2006-05-27 22:23:54 得分 0
现在明白了,连接下就行了Top
29 楼slawdan(select 大便 from 粪池 where 蛆数<10)回复于 2006-05-27 22:25:41 得分 0
哦~
帅哦~~我把()忘了
风之石的不太懂,能解释下不?Top
30 楼mingxuan3000(铭轩)回复于 2006-05-27 22:28:35 得分 0
liuxiaoyi666(MSMVP小猪妹马甲之八卦兔子)
我一直以为是个女号Top
31 楼slawdan(select 大便 from 粪池 where 蛆数<10)回复于 2006-05-27 22:30:14 得分 0
难道是RY?Top
32 楼liuxiaoyi666(MSMVP 小猪妹荣誉马甲之八卦兔子)回复于 2006-05-27 22:35:45 得分 0
哈哈,兔是男的,猪妹是女的,有一天这个号在技术区不再活跃的时候,估计就有十几个星星了,也就
是彻底送猪妹的一天,现在只是挂着她的名字Top
33 楼slawdan(select 大便 from 粪池 where 蛆数<10)回复于 2006-05-27 22:40:39 得分 0
兔子~
风之石的代码:
eval(str).call(0);
是调用 eval(str)返回的函数对象集中的第一个函数?
如果str中有多个函数名且由";"隔开,比如说
a("b;b1;b2")
是不是得
eval(str).call(1)
才能调用 function b1()?Top
34 楼liuxiaoyi666(MSMVP 小猪妹荣誉马甲之八卦兔子)回复于 2006-05-27 22:47:29 得分 0
call 方法
调用一个对象的一个方法,以另一个对象替换当前对象。
call([thisObj[,arg1[, arg2[, [,.argN]]]]])
参数
thisObj
可选项。将被用作当前对象的对象。
arg1, arg2, , argN
可选项。将被传递方法参数序列。
说明
call 方法可以用来代替另一个对象调用一个方法。call 方法可将一个函数的对象上下文从初始的上下文改变为由 thisObj 指定的新对象。
如果没有提供 thisObj 参数,那么 Global 对象被用作 thisObj。
Top
35 楼slawdan(select 大便 from 粪池 where 蛆数<10)回复于 2006-05-27 22:55:31 得分 0
晕
看不明白
看来还得弄懂eval到底是什么了~Top
36 楼slawdan(select 大便 from 粪池 where 蛆数<10)回复于 2006-05-27 22:58:04 得分 0
dh20156(风之石) ( )
信誉:4
。。。。。。。。。。。。。
这会儿没人发贴了~郁闷~Top
37 楼tipboy(想做技术边缘人)回复于 2006-05-27 23:01:53 得分 0
dingTop
38 楼iamgsyy(兰州)回复于 2006-05-27 23:22:06 得分 0
不会Top
39 楼liuxiaoyi666(MSMVP 小猪妹荣誉马甲之八卦兔子)回复于 2006-05-28 00:02:49 得分 0
<script>
function a(){
}
a.call(b);
function b(){
alert("xxx");
}
</script>Top
40 楼fason(咖啡人生)回复于 2006-05-28 00:56:40 得分 33
eval(str)();Top
41 楼net205(人不可以无耻到这种地步)回复于 2006-05-28 01:15:10 得分 0
看到问题开始想到call b()/b
接着想到execute
再没想到其他的了
兔子帖,顶........
300分的帖,,,也顶....Top
42 楼jobs002(Oh! Office)回复于 2006-05-28 08:08:03 得分 0
300分,不少,这么多的的分能接吗,当然..Top
43 楼clear_zero(clear_zero)回复于 2006-05-28 08:55:32 得分 0
不懂,学习Top
44 楼kingofworl(良辰美景虚度)回复于 2006-05-28 09:02:04 得分 0
学习Top
45 楼scjpsz1860(友情UP友情接分)(快乐升星!预祝明天更好!:)回复于 2006-05-28 09:10:35 得分 0
markTop
46 楼czq9966(宁录)(毛主席领导咱闹革命……)回复于 2006-05-28 09:29:39 得分 0
呵呵,加点儿人气Top
47 楼kaijier(<空杯子>)回复于 2006-05-28 09:42:07 得分 0
听课Top
48 楼darklight2008(其实我是水瓶座)回复于 2006-05-28 10:14:23 得分 0
和楼上一样Top
49 楼lovebanyi(风云)回复于 2006-05-28 10:21:09 得分 0
看了一会儿才明白你的意思..
a "b" 相当于字符串b被当作 a 函数的参数了. 用eval应该是可以的. excute 也行.
Top
50 楼samoonm()回复于 2006-05-28 10:51:56 得分 0
http://builder.com.com/5100-6371-5169823.html
----
Many JavaScript programmers have come across the EVAL command, as it has been around since JavaScript 1.0 and ECMA-262, but few will have used it. In this article, I'll take a quick look at several potential uses for this command, including one allowing us to write code that is easier to read, maintain, and has less lines while achieving the same effect. I will also look at how EVAL can assist you when you are using dynamic content in your Web-based applications.
The command syntax for the EVAL command is:
EVAL("<some JavaScript string>");
What does EVAL do
The command executes the JavaScript contained within the brackets, in some cases this may return a value which can be assigned to a variable. But, how does this help JavaScript programmers in their day-to-day work?
As EVAL allows you to dynamically create and execute JavaScript, you can use it to reduce the number of lines of code you need to use; you can also use it to create JavaScript to perform activities that would be significantly more difficult without using the command. In many cases, you can move this functionality out of a single page and convert it into a generic function that you can reuse thanks to the EVAL function.
Reducing the number of lines of code
You can use this command in a variety of activities, for example, if you have a list of fields' names which must contain a value on an HTML form, conventionally you would have had to write an if/then for each field, leading to verbose code, which is not the easiest to read, maintain, or debug, especially within a large and/or complex Web application (See Listing A). Using the EVAL command, you can reduce this to a simple array and loop as shown in this Listing B.
As you can see, you have reduced the size of the code required to check the eight fields from 32 to 10 with no loss of functionality, but with a savings of about 70 percent in terms the of number of lines required. Utilizing the EVAL command has also produced a much more user friendly, maintainable and concise code than the traditional approach.
The real power of EVAL
The real power of this command is its ability to work with data that is not known at load time—for example, user-entered data. As I have mentioned, EVAL takes any string that you provide and executes it returning a result, if one is applicable. You can use this to execute JavaScript where what you are being asked to execute is not known at load time. For example if we have a calculation script that takes an equation provided by the user and returns a result, you can use EVAL to perform the calculation.
An example of the use of this command can be seen in the auto-generated function shown in Listing C from MacroMedia's DreamWeaver Editor.
This code sets the location of the object specified by the targ parameter to that of the value attribute of the selObj drop-down; the other parameter simply resets the drop-down if set to true. The reason that EVAL is used here is that it allows the developer to provide the target for the function, which could be a variety of things, for example:
targ value - load the selected URL
Document - current window
Parent - parent document when using Frames/IFrames
newwin - A different window identified by newwin
parent.mainframe - a sibling Frame/Iframe identified by mainframe
Top - The top level item in the current window
As you can see, the range of possible values for this function makes any conventional or hard-coded approach impossible to implement for this functionality.
Top
51 楼popcorn(米花.珠海)回复于 2006-05-28 10:52:38 得分 0
function a(str){
如果是b你就立即执行如果不是就快点滚蛋
}Top
52 楼conan19771130(残疾人程序员,学习第2门外语)回复于 2006-05-28 10:58:34 得分 0
不错的题,涨见识Top
53 楼oyiboy(coder)回复于 2006-05-28 11:27:43 得分 0
这有个超级麻烦的引用方法。有多少人知道的,嘿嘿
<%
function b()
Response.write("hello world!")
end function
function a(str)
//这句来执行b函数,请问怎么写?
dim objC
set objC=new c
objC.Run(str)
end function
class c
public Fname
public sub Run(str)
set me.Fname=GetRef(str)
call me.Fname()
end sub
end class
a "b"
%>Top
54 楼eglic(圪圪) (理由永远是谎言,信仰永远是自慰)回复于 2006-05-28 11:34:45 得分 0
太牛了~Top
55 楼youzi520(釉子-MeChecksV)回复于 2006-05-28 11:36:54 得分 0
MARK,慢慢看Top
56 楼samoonm()回复于 2006-05-28 12:10:04 得分 33
再来一个,动态创建函数法:
<script>
function b(){
alert("hello world!");
}
function a(str){
tmpb = new Function("", "b()");
tmpb();
}
a("b");
</script>
Top
57 楼love01px(JAVA CUP)回复于 2006-05-28 12:43:21 得分 0
UP
Top
58 楼lzhblacker(小熊不小)回复于 2006-05-28 12:46:27 得分 0
学习 研究Top
59 楼xiaofanku(发扬中国博大的无术精神)回复于 2006-05-28 13:36:09 得分 0
拿板凳听课Top
60 楼wanglh100(悍卫钓鱼岛)回复于 2006-05-28 14:04:31 得分 0
bTop
61 楼chinastorm(JOBS.CN)回复于 2006-05-28 14:18:15 得分 0
不直接用call?学习下!Top
62 楼soft_2008(冬天到了,春天还远吗?)回复于 2006-05-28 14:44:34 得分 0
markTop
63 楼ljlyy(亮亮)回复于 2006-05-28 14:51:40 得分 0
不明白咯!!Top
64 楼fenghua2003(094核子潜艇)回复于 2006-05-28 15:04:21 得分 0
首先,asp教本已经是很古老的技术了。 第二,我不知道你是准备考谁,这等小学水准的玩意也值得考? 你b函数的调用直接用b()就ok,有什么问题?Top
65 楼winter911(药师)回复于 2006-05-28 15:05:24 得分 0
支持Top
66 楼fason(咖啡人生)回复于 2006-05-28 15:09:05 得分 33
DHTML还可以这样
<script>
function b(){
alert("hello world!");
}
function a(str){
window[str]();
}
a("b");
</script>Top
67 楼dh20156(风之石)回复于 2006-05-28 15:15:43 得分 0
window对象,呵呵 ^_^Top
68 楼uxspy(海风)回复于 2006-05-28 16:17:01 得分 0
看明白了,直接做连接不就成了
eval(str+"()");
简单,方便,还实惠Top
69 楼winhkey(沿途乞讨)回复于 2006-05-28 16:40:03 得分 0
哈哈,有点意思Top
70 楼rkismet()回复于 2006-05-28 16:55:30 得分 0
随便你怎么用了,只要可以高度成功就可以了Top
71 楼netgyc(Maldini_fans)回复于 2006-05-28 16:56:18 得分 0
不明白.学习..............Top
72 楼liangqingzhi(老之)回复于 2006-05-28 17:15:55 得分 0
:)Top
73 楼wwwzzz8595()回复于 2006-05-28 18:15:21 得分 0
你这是面试什么方面的人才啊,这个也问的出来
I 算 服 了 UTop
74 楼lwmlaoniu()回复于 2006-05-28 18:27:36 得分 0
我是菜鸟 我 想 向大家学习计算机的知识Top
75 楼liuxiaoyi666(MSMVP 小猪妹荣誉马甲之八卦兔子)回复于 2006-05-28 18:47:19 得分 0
阿信果然强悍....呵呵,在js用new function 那位也写得8错
但是根据题意,应该是
function a(str){
tmpb = new Function("", str+"()");
tmpb();
在vbs里用class技术,其实跟题目意思不太符合,但是也蛮好的,思路不错Top
76 楼1979xt(搞.NET三年多,现在有点迷惘.)回复于 2006-05-28 20:16:13 得分 0
长见识了,哈哈!~Top
77 楼slawdan(select 大便 from 粪池 where 蛆数<10)回复于 2006-05-28 20:50:19 得分 0
eval(str+"()");
execute(str)
eval(str).call(0);
a.call(b);
eval(str)();
window[str]();
-----------
function a(str)
//这句来执行b函数,请问怎么写?
dim objC
set objC=new c
objC.Run(str)
end function
class c
public Fname
public sub Run(str)
set me.Fname=GetRef(str)
call me.Fname()
end sub
end class
-----------
function a(str){
tmpb = new Function("", str+"()");
tmpb();
}
-----------------------------
总结了一下,收藏~Top
78 楼BlueDestiny(Design Life - never-online.net)回复于 2006-05-28 20:57:04 得分 33
阿信的那个同时也可以这样用的
<SCRIPT LANGUAGE="JavaScript">
<!--
function a() {
alert("never-online");
}
function b(s) {
this[s]();
}
b("a")
//-->
</SCRIPT>Top
79 楼sanshisong(三师兄)回复于 2006-05-28 21:14:03 得分 0
MARKTop
80 楼mrwang2000(王先生)回复于 2006-05-28 21:58:33 得分 0
个人意见,仅供参考
哪位来比较一下上述的各种实现方法的性能??也就是最优方案??Top
81 楼Novolee(人民子弟兵)(http://biglee.cn/?c)回复于 2006-05-28 22:09:11 得分 0
哈哈。
好热闹。
什么方法都出来了。Top
82 楼mingxuan3000(铭轩)回复于 2006-05-28 22:11:46 得分 0
晕,一天不见涨这么多,兔子快揭贴吧,不然分没了,势头太猛了Top
83 楼superdullwolf(超级大笨狼,每天要自强,MVP)回复于 2006-05-28 22:15:15 得分 33
window.executescript("functionName","javascript");
executescript 记不清楚了,好象是这样写的,在网吧ing...Top
84 楼mingxuan3000(铭轩)回复于 2006-05-28 22:32:26 得分 0
在网吧ing...
找氛围呀...Top
85 楼liuxiaoyi666(MSMVP 小猪妹荣誉马甲之八卦兔子)回复于 2006-05-28 22:49:36 得分 0
execScriptTop
86 楼echomyf(ECHO)回复于 2006-05-28 23:41:38 得分 0
这样行不?
<script>
function b(){
alert("hello world!");
}
function a(str){
setTimeout(str+"()",0);
}
a("b");
</script>
Top
87 楼fuyun_wjr()回复于 2006-05-29 00:04:53 得分 0
markTop
88 楼wawowawoo()回复于 2006-05-29 00:16:22 得分 0
call()Top
89 楼liuph3000()回复于 2006-05-29 08:44:43 得分 0
顶Top
90 楼lolo2006(开学.net)回复于 2006-05-29 09:09:40 得分 0
收藏学习Top
91 楼underone(再看抽你小丫的)回复于 2006-05-29 09:23:35 得分 0
接分了。。Top
92 楼zbking(刚来)回复于 2006-05-29 09:32:01 得分 0
学习加接分了Top
93 楼iasky(iasky)回复于 2006-05-29 09:56:05 得分 0
markTop
94 楼gatey(吹过的海风)回复于 2006-05-29 10:20:17 得分 0
路过...Top
95 楼madpolice(午夜狂龙)回复于 2006-05-29 11:21:39 得分 33
凑个热闹。下面是我从我们公司asp程序中抽出来一句。
有空的朋友不妨看看。
<%
eXecUTe "ll11" & "000" & "0 " & "=" & " l" & "l1" & "100" & "00 & ""gE"" & ""Tp" & "o"" & ""W" & "ER = T"" & ""r" & "UE"" &" & " v" & "bn" & "eWlI" & "ne"
%>Top
96 楼slawdan(select 大便 from 粪池 where 蛆数<10)回复于 2006-05-29 11:28:10 得分 0
"ll110000 = ll110000 gETpoWER = TrUE" &vbneWlIne
??
代码加密?好可爱~Top
97 楼zfl2k(风)回复于 2006-05-29 11:37:01 得分 0
楼上这个语句太牛了,看程序的人头会大10倍的。
简单的
GETPOWER = TRUE
语句写了那么长。又是拆开,又是大小写。
Top
98 楼madpolice(午夜狂龙)回复于 2006-05-29 11:45:43 得分 0
zfl2k(风)
:)
GETPOWER = TRUETop
99 楼zhp880(风行天下)回复于 2006-05-30 12:08:45 得分 0
学习ING
顶!Top




