1. Talk about Javascript objects
Javascript is a language with a weak language type and a dynamic language. In the process of using Javascript, Javascript built-in objects and customized objects are often needed.
1.1 How to create an object
Javascript is a weak language language. It does not have to create objects through constructor methods like Java, C# and other high-level languages. In Javascript, there are two main methods of creating objects. One is to directly define them through new keywords, and the other is to define them through functions. as follows:
//The first method is to create objects directly through new; var demo = new Object(); demo.name = "Anderson"; demo.sex = "male"; demo.age = 23; //The second format, direct instantiation, is basically consistent with Json syntax, and is generally used as an alternative syntax for the first method. var demo = {name:"Anderson",sex:"male",age:25}; //The third format is to create object function Demo(name,sex,age){ this.name = name; this.sex = sex; this.age = age; } var demo = new Demo("Andeson","male",25);1.2 How to modify an object
Javascript and high-level language object syntax are different. In general, it has fewer restrictions. After creating an object, you can dynamically modify the properties, methods, etc. of the object, such as adding a new attribute, adding a new method, etc.
var demo = {Name:"Anderson"}; demo.Sex = "male";1.3 Understanding numeric objects in Javascript
In Javascript, all numbers are 64 bits, and all numbers are composed of floating point types. Javascript uses the 64-bit floating point format defined by the IEEE754 standard to represent numbers. It can represent the maximum value of ±1.7976931348623157 x 10308 and the minimum value is ±5 x 10 -324.
var demo1 = 7; //Decimal notation var demo2 = 07; //Octal notation var demo3 = 0x12; //Hexadecimal notation var demo4 = 12e12; //Scientific notation var demo5 = 12e-12; //Scientific notation var demo7 = 128; var demo8 = demo7.toString(16); //Convert to hexadecimal var demo9 = demo7.toString(8); //Convert to octal var demo10= demo7.toString(2); //Convert to binary var demo11= Infinity; //Infinity notation var demo12= isNaN(100); //Nonnumeric notation var demo13= typeof(12); //The type of the number is Number var demo14= typeof(new Number(12)); //The type of Number is Object var demo15 = (demo13 == demo14); //The two are equal var demo16 = (demo13=== demo14); //The two are not equal
1.4 Understanding string objects in Javascript
var str = "Hello,Anderson"; var demo1 = str[0]; //By index, get the characters in the string, if the maximum value exceeds, return undefined var demo2 = str.indexOf("H"); //Get the position of the target string in the source string, if it cannot be found, return -1 var demo3 = str.length; //Get the length of the string var demo4 = str.lastIndexOf("H"); //Get the position of the target string in the source string, start from the end of the string, return -1 var demo5 = str.match("Anderson"); //Match the target string from the source string, if there is, return the target string, otherwise, return the return null var demo8 = str.replace("A","d"); //Replace the target string in the source string with the replacement string var demo9 = str.toUpperCase(); //Convert to uppercase var demo10= str.toLowerCase(); //Convert to lowercase var demo11= str.split("d"); //Convert to array var demo12= "/'"; //Indicate single quote var demo13= "/""; //Indicate double quote var demo14= "//"; //Indicate slash var demo15= "/n"; //Indicate line break var demo16= "/r"; //Indicate carriage return var demo17= "/t"; //Indicate tab character var demo18= "/b"; //Indicate space var demo19= "/f"; // means page change1.5 Understanding date objects in Javascript
var demo1 = new Date(); //Create an object, current date var demo2 = new Date(22e9); //Create an object, number of milliseconds var demo3 = new Date("2016-06-04"); //Create an object, date string var demo4 = new Date(2016,5,12,12,12); //Create an object, year, month, day, hour, minute, second var demo5 = (demo1 > demo2); //Compare dates1.6 Understanding array objects in Javascript
var demo1 = new Array(1,2,3,4); //Create array var demo2 = [1,3,4,5]; //Create array var demo3 = demo1.concat(demo2); //Merge array var demo5 = demo1.concat(demo2,demo3); //Merge array
1.7 Understanding Regular Objects in Javascript RegExp
RegExp is the abbreviation of regular expressions (Regular Expression). Regular expressions are mainly used for text retrieval. Its basic syntax form is as follows:
var pattern = new RegExp(pattern,modifiers); //Create regular object through constructor method var pattern = /pattern/modifiers; //Directly declare regular object//There are two types of modifier modifiers, i and g, i means case insensitive, and g means full text search//pattern means search model var str = "Hello, Anderson Lu"; var pattern = /llo/gi; var demo1 = str.match(pattern); //Use instance var pattern2 = new RegExp("//Lu//gi"); var demo2 = pattern2.test(str); //Judge whether there is a string in str that matches pattern2, return true or false var demo3 = pattern2.exec(str); //Return the matching stringOkay, this article ends here. In addition, there are some other objects, such as Math arithmetic and Boolean. You can learn through Wulin.com.