The
Tag:lin ++ default define will also instruction hello attr typeof
If the defined variable is intended to be used to hold the object in the future, it is better to initialize the variable to null instead of the other value, so that if you check the null value directly, you will know whether the corresponding variable has saved a reference to the object Console.info (typeof null)// Object Var a=null; if (a!=null) {//} console.info (Number.max_value,number.min_value) console.info (Number.max_value+number.max_value) +infinity Console.info (Isfinite (Number.max_value+number.max_value))//whether between maximum and minimum var str=new String () console.info (Str.__proto__===string.prototype) Console.info (str.hasownproperty (' length ')) Console.info (str.__proto__. hasOwnProperty (' trim '))//constructor holds the function used to create the current object Console.info (str.constructor===string)//Perform a pre-increment and decrement operation, The value of a variable is a var x=10 that changes before the statement is evaluated and/or the post increment and decrement operations are executed after the statement containing them is evaluated; Console.info (--x-20)//-11 console.info (--x)//8 console.info (x + + +2)//10 console.info (×)//9//comma operator var x=1,y=2, z=3; Performing multiple operations//comma operators can also be used to assign values. When used for assignment, the comma operator always returns the last item in the expression var m= (1,2,3,4,5) Console.info (m) all parameters in//5//ecmascript are passed as values, and arguments cannot be passed by reference. Even if a parameter variable is passed by value, obj accesses the same object by reference//error: The object modified in the local scope is reflected in the global scope, sayingThe argument is passed by reference to function A (halo) {halo.name= "leyi"///by reference to access obj} var obj=new Object ();//ojbj={} a (obj); Console.info (obj.name)//leyi function B (Halo) {halo.name=2; Halo=new Object (); halo.name=4; } var obj2=new Object ();//json={} b (obj2) Console.info (obj2.name)//2//Detect basic type undefined Boolean string number con Sole.info (typeof 123)//number Console.info (typeof "123")//string Console.info (typeof true)//boolean Console.info (typ EOF null)//object//detection determines which reference type a value is used to use the instanceof operator. var a={} var b=[1,2,3] var reg=/.+?/console.info (a instanceof Object)//true console.info (b instanceof Array)//true Console.info (reg instanceof RegExp)//true//The purpose of this method is to finalize whether a value is an array console.info (Array.isarray ([1,2,3,4])) ES5 The array defines 5 iterative methods filter Foreachmapevery//each item in an array runs the given function, and if the function returns true for each item, true some////each item in the array runs the given function if the function returns true for any of the items , true is returned. ES5 also added two ways to merge arrays/* reduce () and reduceright (). Both of these methods iterate over all the items of an algebraic group and then build a value that is ultimately returned. where the reduce () method starts with the first item in the array,Traverse to the last. The Reduceright () begins with the last item in the array and traverses forward to the first */var Arr=[1,2,3,4,5]var allinone=arr.reduce (function (Prev,cur,index,array) {/* Any value returned by the function will be automatically passed to the next item as the first argument. The first iteration occurs on the second item of the array, so the first parameter is the first item of the array (prev), the second parameter is the second item of the array */return prev+cur}) Console.info (ALLinONE)//4 properties of the Data property The Data property contains the location of a data value. Values can be read and written at this location. Modifying the default attributes with Object.defineproperty (obj, prop, descriptor) descriptor contains the following four configuration parameters//configurable can pass delete Deleting an attribute to redefine the property or whether to modify the property to an accessor property Defaults to False//enumerable indicates whether the property can be modified by for-in loop Defaults to False//writable indicates whether the value of the property can be altered Defaults to False//value contains the data value of this property Defaults to undefined var obj={}; Object.defineproperty (obj, ' name ', {configurable:false, Value: "Leyi"}) console.info (obj)//{name: "Leyi"} del Ete obj.name console.info (obj)//{name: The 4 attribute accessor properties of the "leyi"}//Accessor property do not contain data values; they contain a pair of getter and setter functions (both are not required). This is a common way of using accessor properties, where setting the value of one property causes other properties to change//configurable//enumerable//get the function that is called when the property is read. The default value is undefined//set the function that is called when the property is written. The default value is undefined var obj2={attr1: ' Qieizi ', attr2: ' JiUcai "} object.defineproperty (Obj2," Attr3 ", {get:function () {return this.attr1}, Set:function (newval) {if (NE wval== "Qieizi") {this.attr2= "Hello world!"}}}) obj2.attr3= "Qieizi" Console.info (obj2)//{attr1: "Qieizi", attr2: "Hello world!"} Create accessor properties, generally using two nonstandard methods: __definegetter__ () and __definesetter__ ()//Only specify getter means that the property is not writable only the property that specifies the setter function and cannot read Var obj3={_ FLAG:1000,DATE:2017}OBJ3.__DEFINEGETTER__ ("Flag", function () {return this._flag}) obj3.__definesetter__ ("Flag", function (newval) {if (newval>1000) {this._flag=newvalthis.date=2018}}) Obj3.flag=1001console.info (OBJ3)//Define multiple properties Object.defineproperties () var obj4={}object.defineproperties (obj4,{/* Define data Properties */name:{value: "Leyi"},flag:{value:100 },/* Definition Accessor Property */date:{get:function () {return this.name},set:function (newval) {This.flag+=1}}})//object {name: "Leyi" , Flag:100}console.info (OBJ4)//{value:100, Writable:false, Enumerable:false, Configurable:false}console.info ( Object.getownpropertydescriptor (OBJ4, "flag"))//isprototypThe EOf () function is used to indicate whether an object exists in the prototype chain of another object. Returns true if present, otherwise false is returned. Console.info ([Array.prototype.isPrototypeOf]) Console.info (Object.prototype.isPrototypeOf ([i]))// All instances of the prototype chain are pointed to object.prototype//object.getprototypeof () to access the prototype Console.info (Object.getprototypeof ([]))// object.prototype//will error function halo (num) {if (num<4) {return Halo (num+1)}else{return num}} var wor LD =halo; Halo=null; Console.info (World (0))//halo are not a functions//Arguments.callee is a pointer to a function being executed, so it can be used to implement recursive invocation of function haha (n UM) {if (num<4) {return Arguments.callee (num+1)}else{return num}} console.info (haha (0))//error in strict mode, You can use a named function expression to achieve the same result var hehe=function h (Num) {if (num<4) {return H (num+1)}else{return num}} cons Ole.info (hehe (0))
JS Learn from the beginning