To parse an invisible data type in JavaScript

Source: Internet
Author: User
Tags bind

  This article is mainly about the invisible data types in JavaScript in detail, the need for friends can come to the reference, I hope to help you.

JS provides some built-in objects, functions, and constructors for programming, such as math, parseint, object, array, and so on. These are visible and can be used in programming. For example, I can new Object or new Array.   Some are not visible, and these objects can only be provided by the engine in a particular situation. These types of objects are often reduced to a number of functions. The following list of some   Arguments types Arguments types cannot be created manually by programmers, that is, you cannot create a new Arguments (). It has and only one object arguments     copy code code as follows: function func () {      Console.log (arguments[0))     1      Console.log (arguments.length)//3 }  func (1, 2, 3)     Arguments object is created at the time of function call Built, visible and used only within functions. You can see that arguments is very much like an array, you can index elements and the length property. But it is not array, it has no array of some methods such as push, pop and so on. Arguments is defined in ES5 10.6.   Two, the function returned by BIND is very special bind is a new method that ES5 gives Function.prototype, which is called directly on the function like call/apply. It returns a function that specifies the context and parameters.     Copy code code as follows: function func (age) {      Console.log (' name: ' + THIS.name + ', career: ' + age ') &N Bsp }  var person = {name: ' John McCarthy '}  var f1 = func.bind (person, ' computer scientist ')   F1 ()//Name:jo HN McCarthy, Career:computer scientist    You can see that the returned function F1 the same as the normal function using parentheses to execute the call. Everything's fine, but the following code will get you in a big surprise. Copy code code as follows: function func (age) {      Console.log (' name: ' + THIS.name + ', career: ' + A GE)  }  var person = {name: ' John McCarthy '}  var f1 = func.bind (person, ' computer scientist ')   CONSOL E.log (F1.prototype)//undefined    and the code above, the last sentence is different, did not perform F1 (), but print out f1.prototype, found to be undefined.   Strange? Does each function have a prototype attribute, which is used to implement the prototype inheritance Oh. Indeed, the function returned by bind is rather special, and it has no prototype. This special function is created by the JS engine, and the client programmer is not able to use the function declaration or the direct amount of the function.   This point is clearly indicated in the specification ES5 15.3.4.5  
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.