boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 谁给讲讲这javascript代码
相关主题
因为maven,又折腾了一遍variables,够呛
Python真是一种长得很丑的语言
static function and static variable?
how to change a variable's value in a const function
an interview question
关于inline function里的static variable
请教一个javascript的问题
我的matlab 抽风了。。。。
C language的functoin-based reuse的问题(概念级的)
请问在ASP.net中用Javascript的一个问题
相关话题的讨论汇总
话题: ods话题: oac话题: function话题: return话题: var
进入Programming版参与讨论
1 (共1页)
g*****g
发帖数: 34805
1
YAHOO.example.FnMultipleFields = function() {
var oDS = new YAHOO.util.FunctionDataSource(matchNames);
var oAC = new YAHOO.widget.AutoComplete("myInput", "myContainer", oDS);
return {
oDS : oDS,
oAC : oAC
};
}();
FnMultiFields 到底是个类还是个变量?这个return什么意思,还有最后的括号。
或者这就像java的匿名类?
m******t
发帖数: 2416
2

It's a variable holding a reference to the function defined here.
Similar to the function pointer in C, or the (upcoming) closure
in Java.
Return returns the return value of the function, which is an object/map
defined on the fly with two properties.
The last () is also part of the function declaration.

【在 g*****g 的大作中提到】
: YAHOO.example.FnMultipleFields = function() {
: var oDS = new YAHOO.util.FunctionDataSource(matchNames);
: var oAC = new YAHOO.widget.AutoComplete("myInput", "myContainer", oDS);
: return {
: oDS : oDS,
: oAC : oAC
: };
: }();
: FnMultiFields 到底是个类还是个变量?这个return什么意思,还有最后的括号。
: 或者这就像java的匿名类?

g*****g
发帖数: 34805
3
最后这个()还是不明白,定义一个变量指向函数我理解。
但不应该是
xx = function(){return ....};就够了?

【在 m******t 的大作中提到】
:
: It's a variable holding a reference to the function defined here.
: Similar to the function pointer in C, or the (upcoming) closure
: in Java.
: Return returns the return value of the function, which is an object/map
: defined on the fly with two properties.
: The last () is also part of the function declaration.

m******t
发帖数: 2416
4

Heh, to be honest, I don't quite get it either. I'm sort of
just taking it for granted that it's just how javascript
works.
What's the javascript guru around here?

【在 g*****g 的大作中提到】
: 最后这个()还是不明白,定义一个变量指向函数我理解。
: 但不应该是
: xx = function(){return ....};就够了?

s******n
发帖数: 876
5
invoking the function, duh!

【在 m******t 的大作中提到】
:
: Heh, to be honest, I don't quite get it either. I'm sort of
: just taking it for granted that it's just how javascript
: works.
: What's the javascript guru around here?

g*****g
发帖数: 34805
6
revisiting it, it's probably equivalent to
var temp = function(){};
YAHOO.example.FnMultipleFields = temp();
So YAHOO.example.FnMultipleFields is not a function pointer, but the return
value of that function. Now it makes more sense. It's like anonymous inner
class in Java, the object is never named but an instance is created.

【在 m******t 的大作中提到】
:
: Heh, to be honest, I don't quite get it either. I'm sort of
: just taking it for granted that it's just how javascript
: works.
: What's the javascript guru around here?

g**e
发帖数: 6127
7
好虫解释的好

return

【在 g*****g 的大作中提到】
: revisiting it, it's probably equivalent to
: var temp = function(){};
: YAHOO.example.FnMultipleFields = temp();
: So YAHOO.example.FnMultipleFields is not a function pointer, but the return
: value of that function. Now it makes more sense. It's like anonymous inner
: class in Java, the object is never named but an instance is created.

m******t
发帖数: 2416
8

LOL, duh exactly.

【在 s******n 的大作中提到】
: invoking the function, duh!
h*********o
发帖数: 62
9
YAHOO.example.FnMultipleFields is a js static variable.
without extra (), it would be a definition for a static function that
returns a Jason type object.
X****r
发帖数: 3557
10
Exactly. The code is almost the same as
var oDS = new YAHOO.util.FunctionDataSource(matchNames);
var oAC = new YAHOO.widget.AutoComplete("myInput", "myContainer", oDS);
YAHOO.example.FnMultipleFields = {oDS : oDS, oAC : oAC};
Except that the variable oDS and oAC are never introduced in the global
(or current) scope.

return
inner

【在 g*****g 的大作中提到】
: revisiting it, it's probably equivalent to
: var temp = function(){};
: YAHOO.example.FnMultipleFields = temp();
: So YAHOO.example.FnMultipleFields is not a function pointer, but the return
: value of that function. Now it makes more sense. It's like anonymous inner
: class in Java, the object is never named but an instance is created.

1 (共1页)
进入Programming版参与讨论
相关主题
请问在ASP.net中用Javascript的一个问题
感觉学了Javascript之后看Ruby就是个toy
C#是坑吗?还是应该坚持java
javascript真是太爽了
Javascript的Scope问题
请教一下:Javascript callback not working
请教个javascript的问题 (转载)
如何定义 Javascript overload function ?
又一道面试题,我是不是想多了?
What is "number of bits set"?
相关话题的讨论汇总
话题: ods话题: oac话题: function话题: return话题: var