Array.prototype.slice.call self

In order to study Currying in Javascript, read a lot of foreign language website, is to find a better Currying program, find the following in more detail (the article may contain internal links to more related articles):

  1. Currying JavaScript Functions
  2. JavaScript Currying Redux
  3. JavaScript currying
  4. 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:
Update: The following write may be a bit difficult to understand, fear of people who may be new to Javascript can not read, please leave a message after reading it, thank you!

Array.prototype.slice.call (thisArg [, arg1 [, arg2 [, ...]]])

Members on:

Array [object]

Array objects (that is, an array of objects)

prototype [property]

Javascript's prototype, the prototype non-Prototype.js, may for the time being understood as Java, static properties / methods. In short it can not say in detail see JavaScript in the prototype (prototype) Attribute.

slice [Function]

Segmentation of the array, a method useful, concrete look here or there .

call [Function]

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.

Effect of:
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.

Mechanism:
Here is a Function object slice method. Typically, the programmer through the following method call Function, in essence, an ordinary function call method:

Array.slice(begin,end)

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:

Array.prototype.slice.call(obj,begin,end)

Using pseudo-code simulation process:

Well, we use pseudo-code to simulate the entire process:

var mySlice=Array.prototype.slice;

alert(mySlice); //alert: function(begin[,end]){...}, This is a "function  "

var array_empty=mySlice(begin,end); //create a new,empty array

set array_empty=obj; // At this point, bring  obj Assigned to the empty array, the array has a seed  ,
                              // This is the  call() Are doing, "artificial insemination  "

alert(array_empty); // This is not an array of type object, the  Javascript Internal control over  ,
                           // This may be nothing to see, but the outcome of the case  , It must be related with obj  

// The following are the key of a row  :
var array_last=array_empty.slice(begin,end);
/**
* Although before that asensitive  ,
* However, the returned array is an array, we cut  , But what to cut  ?
* Yes, you can take with  obj Created by array conducting cutting  ,
* A new array object produced  !
*/

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) .

Related Reading:

[1] Array.prototype.slice.apply Tips

[2] Array-like Objects in JavaScript .

分类:Web 时间:2010-08-26 人气:194
分享到:
blog comments powered by Disqus

相关文章

  • draggable.js source code analysis 2010-12-01

    /** * draggable - jQuery EasyUI * * Licensed under the GPL: * http://www.gnu.org/licenses/gpl.txt * * Copyright 2010 stworthy [ stworthy@gmail.com ] */ (function($){ // Method of moving variables stored function drag(e){ var opts = $.data(e.data.targ

  • (Transfer) MapReduce source code analysis summary 2011-05-03

    Original Address: http://www.cnblogs.com/end/archive/2011/04/26/2029499.html Transferred by Note: The summary originally wanted to study in the series of detailed analysis Hadoop HDFS and Map-Reduce, however, when searching for information and found

  • JQuery source code analysis-each transfer function 2010-07-24

    / *! * JQuery source code analysis-each function * JQuery version: 1.4.2 * * ------------------------------------------------- --------- * Function description * * Each function by jQuery.extend function attached to the jQuery object: * JQuery.extend

  • Spring Framework core source code analysis and experience-IOC articles -4 2010-11-13

    From the article, I know we want to get the Bean is instantiated out how, but also know that dependency injection actually occurred in the BeanWrapperImpl this class, and then we look at the implementation of this class (that is applyPropertyValues (

  • Spring source code analysis (6): Spring declarative transaction processing 2009-11-30

    We take a look at Spring's transaction code, the use of Spring Management Services are two kinds of declarative and programmatic way through the AOP declarative transaction management code to achieve the things as a package to horizontal aspects of t

  • Spring source code analysis (8): Spring-driven implementation of Hibernate 2009-03-26

    O / R tool came to simplify the complex information of many persistent development. Spring application developers through the Spring provides O / R program is more convenient to use a variety of persistence tools, such as Hibernate; Here we have Spri

  • Android IPC communication mechanism for source code analysis 2010-06-10

    Android IPC communication mechanism for source code analysis Binder Communications Description: Linux system, inter-process communication methods are: socket, named pipe, message queque, signal, share memory. Java System inter-process communication w

  • (R) linux source code analysis and comparative reading tools 2010-11-01

    Reprinted from: http://hi.baidu.com/likeadream/blog/item/7664bb349daf0049241f144c.html Windows source code under the reading tool Souce Insight by virtue of its ease of use and variety of programming languages, this area is undoubtedly the "take the

  • NMAP-3.75 source code analysis (1. The whole process) 2010-11-03

    From nmap.cc file nmap_main () function begins 307 line: while((arg = getopt_long_only(argc,fakeargv,"6Ab:D:d::e:Ffg:hIi:M:m:NnOo:P:p:qRrS:s:T:Vv", long_options, &option_index)) != EOF) { start parsing command line parameters, according to t

  • (R) linux source code analysis tools, and read more 2010-11-01

    Reprinted from: http://hi.baidu.com/likeadream/blog/item/7664bb349daf0049241f144c.html Reading tool for Windows source code Souce Insight With its ease of use and a variety of programming languages, no doubt in this area, "lead Big Brother." Lin

iOS 开发

Android 开发

Python 开发

JAVA 开发

开发语言

PHP 开发

Ruby 开发

搜索

前端开发

数据库

开发工具

开放平台

Javascript 开发

.NET 开发

云计算

服务器

Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 黔ICP备15002463号-1

processed in 0.519 (s). 12 q(s)