The function () of the method that can be executed when the function is defined in Ext.js () {...} () JS Code
- /**
- * Part Two function: The function of the method that can be executed at the time of definition () {...} (); Note that after the red parenthesis , the function definition, the price brackets are defined and then executed
- */
- /**
- * I. Definition and execution of common methods
- */
- 1-1, normal method definition, without the return value of the case
- Fun = function () {
- Alert ("execute");
- };
- 1-2, normal method execution, without the return value of the case
- Fun ();//output Result: Execute
- 2-1, normal method definition, with return value, and the return value is a string case
- Fun = function () {
- Alert ("execute");
- Return "is the string returned";
- }
- 2-2, normal method execution, with the return value, and the return value is a string case
- Fun ();//output Result: Execute
- 2-3, the normal method executes, with the return value, and the return value is a string case, and the return value output
- Alert (fun ());//output: Execute, return the string, (two warning boxes appear), because the fun () is executed first, and then bring back the returned string, and then through the alert output
- Alert (typeof fun ());//Output Result: Execute, string
- 3-1, normal method definition, with return value, and the return value is an object case
- Fun = function () {
- Alert ("execute");
- return new Date ();
- }
- 3-2, normal method execution, with the return value, and the return value is an object case
- Fun ();//output Result: Execute
- 3-3, the normal method executes, with the return value, and the return value is an object case, and the return value output
- Alert (fun ());//Output Result: Execute, Wed may 16:25:32 utc+0800 2008
- 3-4, the normal method executes, with the return value, and the return value is an object case, and the return value type output
- Alert (typeof fun ());//Output Result: Execute, Object
- 4-1, normal method execution, with the return value, and the return value is a function of the case
- Fun = function () {
- Alert ("execute");
- return function () {
- Alert ("return type is a method");
- };
- }
- 4-2, normal method execution, with the return value, and the return value is a function of the case
- Fun ();//output Result: Execute
- 4-3, because Fun () is returned after execution of a function, so according to the function of the returned parameter conditions (such as the number and type of parameters) to perform a return function,
- Because the returned function here does not require parameters, it can be executed directly with ().
- Fun () ();//Output result: execution, return type is a method
- 3-4, the normal method executes, with the return value, and the return value is an object case, and the return value type output
- Alert (typeof fun ());//Output Result: Execute, function
- /**
- * Can be executed when defined
- */
- Fun = function () {
- Alert ("execute");
- }();
- alert (fun);
- Fun = function () {
- Alert ("execute");
- Return "is the string returned"; A string is returned.
- }();
- Alert (Fun)
- Fun = function () {
- Alert ("execute");
- return new Date (); It returns an object.
- }();
- alert (fun);
- Fun = function () {
- Alert ("execute");
- return function () {
- Alert ("return type is a method");
- }//Returned is a method
- }();
- Fun ();
Original link: http://yahaitt.iteye.com/blog/193054
ExtJS Basic--function The method that can be executed at the time of definition Function () {...} ()