X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/6746dc89c47ed01b165cc1152533605f97eb8e8d..f562e4c6e5fac7bcb445985b99acbea4d706e6f0:/docs/output/Function.js diff --git a/docs/output/Function.js b/docs/output/Function.js new file mode 100644 index 00000000..32ca5e95 --- /dev/null +++ b/docs/output/Function.js @@ -0,0 +1 @@ +Ext.data.JsonP.Function({"tagname":"class","html":"

Files

Every function in JavaScript is actually a Function object.

\n\n

Function objects created with the Function constructor are parsed when the\nfunction is created. This is less efficient than declaring a function and\ncalling it within your code, because functions declared with the function\nstatement are parsed with the rest of the code.

\n\n

All arguments passed to the function are treated as the names of the\nidentifiers of the parameters in the function to be created, in the order in\nwhich they are passed.

\n\n

Invoking the Function constructor as a function (without using the new\noperator) has the same effect as invoking it as a constructor.

\n\n

Specifying arguments with the Function constructor

\n\n

The following code creates a Function object that takes two arguments.

\n\n
// Example can be run directly in your JavaScript console\n\n// Create a function that takes two arguments and returns the sum of those\narguments\nvar adder = new Function(\"a\", \"b\", \"return a + b\");\n\n// Call the function\nadder(2, 6);\n// > 8\n
\n\n

The arguments \"a\" and \"b\" are formal argument names that are used in the\nfunction body, \"return a + b\".

\n\n
\nDocumentation for this class comes from MDN\nand is available under Creative Commons: Attribution-Sharealike license.\n
\n\n
Defined By

Properties

 

Specifies the number of arguments expected by the function.

\n

Specifies the number of arguments expected by the function.

\n
Defined By

Methods

new( String... args, String functionBody ) : Object
Creates new Function object. ...

Creates new Function object.

\n

Parameters

  • args : String...

    Names to be used by the function as formal argument names. Each must be a\nstring that corresponds to a valid JavaScript identifier or a list of such\nstrings separated with a comma; for example \"x\", \"theValue\", or \"a,b\".

    \n
  • functionBody : String

    A string containing the JavaScript statements comprising the function\ndefinition.

    \n

Returns

Applies the method of another object in the context of a different object (the\ncalling object); arguments can be pass...

Applies the method of another object in the context of a different object (the\ncalling object); arguments can be passed as an Array object.

\n\n

You can assign a different this object when calling an existing function. this refers to the\ncurrent object, the calling object. With apply, you can write a method once and then inherit it\nin another object, without having to rewrite the method for the new object.

\n\n

apply is very similar to call, except for the type of arguments it supports. You can use an\narguments array instead of a named set of parameters. With apply, you can use an array literal, for\nexample, fun.apply(this, ['eat', 'bananas']), or an Array object, for example, fun.apply(this,\nnew Array('eat', 'bananas')).

\n\n

You can also use arguments for the argsArray parameter. arguments is a local variable of a\nfunction. It can be used for all unspecified arguments of the called object. Thus, you do not have\nto know the arguments of the called object when you use the apply method. You can use arguments\nto pass all the arguments to the called object. The called object is then responsible for handling\nthe arguments.

\n\n

Since ECMAScript 5th Edition you can also use any kind of object which is array like, so in\npractice this means it's going to have a property length and integer properties in the range\n[0...length). As an example you can now use a NodeList or a own custom object like {'length': 2,\n'0': 'eat', '1': 'bananas'}.

\n\n

You can use apply to chain constructors for an object, similar to Java. In the following example,\nthe constructor for the Product object is defined with two parameters, name and value. Two\nother functions Food and Toy invoke Product passing this and arguments. Product\ninitializes the properties name and price, both specialized functions define the category. In\nthis example, the arguments object is fully passed to the product constructor and corresponds to\nthe two defined parameters.

\n\n
function Product(name, price) {\n    this.name = name;\n    this.price = price;\n\n    if (price < 0)\n        throw RangeError('Cannot create product \"' + name + '\" with a negative price');\n    return this;\n}\n\nfunction Food(name, price) {\n    Product.apply(this, arguments);\n    this.category = 'food';\n}\nFood.prototype = new Product();\n\nfunction Toy(name, price) {\n    Product.apply(this, arguments);\n    this.category = 'toy';\n}\nToy.prototype = new Product();\n\nvar cheese = new Food('feta', 5);\nvar fun = new Toy('robot', 40);\n
\n\n

Clever usage of apply allows you to use built-ins functions for some tasks that otherwise\nprobably would have been written by looping over the array values. As an example here we are going\nto use Math.max/Math.min to find out the maximum/minimum value in an array.

\n\n
//min/max number in an array\nvar numbers = [5, 6, 2, 3, 7];\n\n//using Math.min/Math.max apply\nvar max = Math.max.apply(null, numbers); // This about equal to Math.max(numbers[0], ...) or\n// Math.max(5, 6, ..)\nvar min = Math.min.apply(null, numbers);\n\n//vs. simple loop based algorithm\nmax = -Infinity, min = +Infinity;\n\nfor (var i = 0; i < numbers.length; i++) {\nif (numbers[i] > max)\n    max = numbers[i];\nif (numbers[i] < min)\n    min = numbers[i];\n}\n
\n\n

But beware: in using apply this way, you run the risk of exceeding the JavaScript engine's\nargument length limit. The consequences of applying a function with too many arguments (think more\nthan tens of thousands of arguments) vary across engines, because the limit (indeed even the nature\nof any excessively-large-stack behavior) is unspecified. Some engines will throw an exception. More\nperniciously, others will arbitrarily limit the number of arguments actually passed to the applied\nfunction. (To illustrate this latter case: if such an engine had a limit of four arguments [actual\nlimits are of course significantly higher], it would be as if the arguments 5, 6, 2, 3 had been\npassed to apply in the examples above, rather than the full array.) If your value array might grow\ninto the tens of thousands, use a hybrid strategy: apply your function to chunks of the array at a\ntime:

\n\n
function minOfArray(arr)\n{\n    var min = Infinity;\n    var QUANTUM = 32768;\n    for (var i = 0, len = arr.length; i < len; i += QUANTUM)\n    {\n        var submin = Math.min.apply(null, numbers.slice(i, Math.min(i + QUANTUM, len)));\n        min = Math.min(submin, min);\n    }\nreturn min;\n}\n\nvar min = minOfArray([5, 6, 2, 3, 7]);\n
\n

Parameters

  • thisArg : Object

    The value of this provided for the call to fun. Note that this may not be\nthe actual value seen by the method: if the method is a function in non-strict mode code, null and\nundefined will be replaced with the global object, and primitive values will be boxed.

    \n
  • argsArray : Array

    An array like object, specifying the arguments with which fun should be\ncalled, or null or undefined if no arguments should be provided to the function.

    \n

Returns

  • Object

    Returns what the function returns.

    \n
Calls (executes) a method of another object in the context of a different\nobject (the calling object); arguments can ...

Calls (executes) a method of another object in the context of a different\nobject (the calling object); arguments can be passed as they are.

\n\n

You can assign a different this object when calling an existing function. this refers to the\ncurrent object, the calling object.

\n\n

With call, you can write a method once and then inherit it in another object, without having to\nrewrite the method for the new object.

\n\n

You can use call to chain constructors for an object, similar to Java. In the following example,\nthe constructor for the product object is defined with two parameters, name and value. Another\nobject, prod_dept, initializes its unique variable (dept) and calls the constructor for\nproduct in its constructor to initialize the other variables.

\n\n
function Product(name, price) {\n    this.name = name;\n    this.price = price;\n\n    if (price < 0)\n        throw RangeError('Cannot create product \"' + name + '\" with a negative price');\n    return this;\n}\n\nfunction Food(name, price) {\n    Product.call(this, name, price);\n    this.category = 'food';\n}\nFood.prototype = new Product();\n\nfunction Toy(name, price) {\n    Product.call(this, name, price);\n    this.category = 'toy';\n}\nToy.prototype = new Product();\n\nvar cheese = new Food('feta', 5);\nvar fun = new Toy('robot', 40);\n
\n\n

In this purely constructed example, we create anonymous function and use call to invoke it on\nevery object in an array. The main purpose of the anonymous function here is to add a print\nfunction to every object, which is able to print the right index of the object in the array.\nPassing the object as this value was not strictly necessary, but is done for explanatory purpose.

\n\n
var animals = [\n{species: 'Lion', name: 'King'},\n{species: 'Whale', name: 'Fail'}\n];\n\nfor (var i = 0; i < animals.length; i++) {\n    (function (i) {\n    this.print = function () {\n        console.log('#' + i  + ' ' + this.species + ': ' + this.name);\n    }\n}).call(animals[i], i);\n}\n
\n

Parameters

  • thisArg : Object

    The value of this provided for the call to fun.Note that this may not be\nthe actual value seen by the method: if the method is a function in non-strict mode code, null\nand undefined will be replaced with the global object, and primitive values will be boxed.

    \n
  • args : Object...

    Arguments for the object.

    \n

Returns

  • Object

    Returns what the function returns.

    \n
Returns a string representing the source code of the function. ...

Returns a string representing the source code of the function. Overrides the\nObject.toString method.

\n\n

The Function object overrides the toString method of the Object object; it does\nnot inherit Object.toString. For Function objects, the toString method returns a string\nrepresentation of the object.

\n\n

JavaScript calls the toString method automatically when a Function is to be represented as a\ntext value or when a Function is referred to in a string concatenation.

\n\n

For Function objects, the built-in toString method decompiles the function back into the\nJavaScript source that defines the function. This string includes the function keyword, the\nargument list, curly braces, and function body.

\n

Returns

  • String

    The function as a string.

    \n
","allMixins":[],"meta":{},"requires":[],"deprecated":null,"extends":null,"inheritable":false,"static":false,"superclasses":[],"singleton":false,"code_type":"nop","alias":null,"statics":{"property":[],"css_var":[],"css_mixin":[],"cfg":[],"method":[],"event":[]},"subclasses":[],"uses":[],"protected":false,"mixins":[],"members":{"property":[{"tagname":"property","deprecated":null,"static":false,"owner":"Function","template":null,"required":null,"protected":false,"name":"length","id":"property-length"}],"css_var":[],"css_mixin":[],"cfg":[],"method":[{"tagname":"method","deprecated":null,"static":false,"owner":"Function","template":false,"required":null,"protected":false,"name":"constructor","id":"method-constructor"},{"tagname":"method","deprecated":null,"static":false,"owner":"Function","template":false,"required":null,"protected":false,"name":"apply","id":"method-apply"},{"tagname":"method","deprecated":null,"static":false,"owner":"Function","template":false,"required":null,"protected":false,"name":"call","id":"method-call"},{"tagname":"method","deprecated":null,"static":false,"owner":"Function","template":false,"required":null,"protected":false,"name":"toString","id":"method-toString"}],"event":[]},"private":false,"component":false,"name":"Function","alternateClassNames":[],"id":"class-Function","mixedInto":[],"xtypes":{},"files":[{"href":"Function.html#Function","filename":"Function.js"}]}); \ No newline at end of file