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