- functional.js description and source code analysis
Found that most people are used Array.prototype.slice.call (argments, 0), had not understand what the sentence is. The last revision of the slice () method, then reference Function.call (thisArg [, arg1 [, arg2 [, ...]]]) , or do not know (I brain turn slowly: |). Internet search, check first foreigner to Google.com in English did not explain, really to find the "Array.prototype.slice use" only when they get a few articles . While I despise people who engage in collecting, and made the Internet a great copy paper like the world like, but now hate less, only three (exactly the same three, editor for the admin or super-administrator, the author is Anonymous. )
Here my understanding, Array.prototype.slice.call to explain, rookie left, prawn spit:
Array.prototype.slice.call (thisArg [, arg1 [, arg2 [, ...]]])
Array objects (that is, an array of objects)
Magic method, which is all the Function object in the way, so there is a method of slice. Function object used to replace inside this target. See here .
String up is:
Use human language to say that the Array has a prototype, slice is the prototype of his son, call a slice of his wife (a lot of bricks came.) Please continue to look down.
Array.prototype.slice.call == .slice
Although the result is a kind of running, but after testing (others to do the test, not me), the efficiency of the former than the latter greatly improved, so it is so applied.
Here is a Function object slice method. Typically, the programmer through the following method call Function, in essence, an ordinary function call method:
As for the call () method, METHOD: Function:: call us, you can
Function.call(thisArg[, arg1[, arg2[, ...]]])
In the form of calling a Function object, this object among Replace thisArg, which can be the following code:
Using pseudo-code simulation process:
Well, we use pseudo-code to simulate the entire process:
Similarly, Array.prototype.slice.apply (obj) and similar code can also be understood that, as long as the prototype not interfere on the line. See here do not understand them, please review the Array.slice (begin, End) .