Function. Prototype. Bind knowledge point

Source: Internet
Author: User

 

1 var addnum = {// create a method and add num 2 num: 5, 3 fun: function (VAL) {4 return this. num + val; 5} 6} 7 8 function. prototype. bind = function (OBJ) {// function is an object, prototype. BIND is to add a new method 9 VaR method = This; 10 return function () {11 return method. apply (OBJ, arguments); 12} 13} 14 15 var foo1 = addnum. fun (3); 16 17 var addjson = {18 num: 1019}; 20 var foo2 = addnum. fun. BIND (addjson); 21 22 console. log (foo1); // The 823 console. log (foo2 (3); // 13

 

 

 

The bind and apply methods have been mentioned in the previous article. Please refer to the corresponding link.

Http://www.cnblogs.com/johnnylion/p/3937325.html

Http://www.cnblogs.com/johnnylion/p/3937456.html

 

Data Type

There are 6 data types in ecmascript. Includes five simple data types (also known as basic data types) and one complex data type.

 

Simple data type:
Undefined | null | Boolean | Number | string

 

Complex data types:
Object

 

Typeof Operator

Typeof can detect the Data Type of a given variable. Using the typeof operator for a value may return one of the following strings:

Undefined: if this value is undefined

Boolean: ***** Boolean

String: ***** string

Number: ***** Value

Object: * or null

Function: ***** Function

 

Example

var message = "some string";console.log(typeof message); // stringconsole.log(typeof (message)); // stringconsole.log(typeof 95); // number

 

Instanceof

O instanceof type: determines whether the object o belongs to the type. If O is an instance of the type subclass, it is also satisfied.

Example

1 var o=[];2 console.log(o instanceof Array); // true3 console.log(o instanceof Object); // true4 var f=function(){}5 console.log(f instanceof Function); // true6 console.log(f instanceof Object); // true

 

 

Reference similar to object | array | date | Regexp | Function

 

Function. Prototype. Bind knowledge point

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.