[Tutorial] Variables in JScript Quote (Supplement, Function Usage) By http://www.lostinet.com/ ,http://lostinet.d2g.com
First: http://www.9cbs.net/expert/topic/787/787738.xml
My college entrance examination language is only 496 points ,,, it is miserable. . I have to say something now, I don't know. . . Still use the example: just examples and analysis, it is now written.
This is just supplementary, and it doesn't matter if you don't look. Will it still look at it :)
2.1 - "The function is transmitted {- {- {--- {- {- {- {- {- {- {- {- {- {- {- { - {- {- {- {- {- {- VAR func = function () {Alert ("OK")}; function callfunc (f) {f ();} CallFunc FUNC); ---} ---} ---} ---} ---} ---} ---} ---} ---} ---} ---} --- } ---} ---} ---} ---} The transfer function is rare. But for a lot of dynamic applications, the transfer function is normal. This example, FUNC is a function. When CallFunc (FUNC), the FUNC is passed to the f in the callfunc, so f is a function in function callfunc (f) {f ();}. So call f () is ok. In fact, call function () {alert ("ok")};
2.2 - "Function as method {- {- {- {- {- {--- {- {- {- {- {- {- - {- {--- {--- {- {--- var obj = {}; // var obj = new object (); obj.value = 14; var func = function (Number ) {Alert (this.Value Number)}; obj.alert = func; obj.alert (25); ---} ---} ---} ---} ---} ---} - -} ---} ---} ---} ---} ---} ---} ---} ---} ---}
This example, how the function is used as an object, how is it used. This is a special variable that is a parameter. When Obj.Alert (25) is executed, it is actually executing function (Number) {Alert (this.Value Number)}; and the OBJ is also transmitted in this process, and incorporated into this. Everyone knows, so don't say much. There are only two ways to perform objects: 1: Obj.method (); there must be a "." Existence. 2: Func.Apply (Obj, Args), Func.call (Obj, Arg1, Arg2 ...), this requires JScript5.5 support.
2.3 - "Function as method, 2 {- {--- {- {- {- {- {- {- {- {- {- {- {--- {- {--- {- {- {- {--- var obj =}; // var obj = new object (); obj.value = 14; var func = function (Number) {Alert (this.Value Number)}; obj.alert = func; var method = obj.alertmethod (4); ---} ---} ---} ---} ---} ---} ---} ---} ---} ---} ---} ---} ---} ---} ---} ---}
Why show nan? Although Method = Obj.alert, but passed, it is just obj ["alert"] itself, that is, func, in executing FUNC, there is no implicit object pass to thisthis is not assigned, in IE, default is Window, Other variable spaces rely on the space with THIS to determine 2.4 - "functions as object use. {- {--- {--- {- {- {- {- {- {- {- {- {- {- {- {- {- {- { - {- {--- {- function aaa () {Alert (this);} function aaa.bbb () {Alert (this);} var func = function () {}; func.bbb = aaa; func.bb (func.bbb.bb (); ---} ---} ---} ---} ---} ---} ---} ---} - -} ---} ---} ---} ---} ---} ---} ---} I have no spirit, you understand it. .
2.5 - "The function is used as the object 2. {- {--- {--- {- {- {- {- {- {- {- {- {- {- {- {- {- {- { - {--- {--- {--- function func () {}; function func.a () {Return "a"}; function func.b () {return "b"}; function func. c () {RETURN "C"}; for (var i in func) Alert (FUNC [I] ()); ---} ---} ---} ---} ---} --- } ---} ---} ---} ---} ---} ---} ---} ---} ---} ---}
2.6 - "Caller {- {- {- {- {- {- {- {- {- {--- {- {--- {- {- {--- {--- {- function func () {alert (func.caller);} function callfunc () {Alert (callfunc.caller); func (); Callfunc (); ---} ---} ---} ---} ---} ---} ---} ---} ---} ---} ---} - -} ---} ---} ---} ---} Because CallFunc () is globally executed, there is no function calls CallFunc, so callfunc.caller is NULL, which is called by callfunc, so Second display CallFunc
2.7 - "Do not rely on the name, take a function in the function itself {- {- {- {- {- {- {- {- {- {- {- {- - {- {--- {- {--- {- {- {--- function callfunc () {Alert (callfunc); var fs = function (function (fs) {Return FS. Caller}; fs = fs (fs); Alert (fs);} callfunc (); ---} ---} ---} ---} ---} ---} ---} - -} ---} ---} ---} ---} ---} ---} ---} ---} The first ALERT is a demonstration. This is directly to CallFunc. VAR FS defines a very special function. When fs = fs (fs) is executed, the FS caller CallFunc is retrieved, so the fs references CallFunc.
2.8 - "arguments {--- {- {--- {- {- {- {- {- {- {- {--- {- {- {--- {- {- {- {- {- {var args = alertbatch.Arguments; var arr = []; for (var i = 0; i There are not many other aspects of the function. The reference books of JScript have instructions.