1, the data type in JS
Primitive Type: string, numeric Number, Boolean Boolean, null undefined. Where null means no object, undefined indicates no definition
Arrays Array Object
2. Create objects:
1. Create an object from the New keyword
var obj=new Object ();
Obj.name= "";
obj.age=18;
Obj.todo=function () {}
2. By object literal
2.1 Simple literal
var obj2={};
Obj2.name= "";
Obj2.todo=function () {return this.name;}
2.2 Nested literals (recommended)
var obj3={name: "", Age:18,todo:function () {},run:function () {}}
If there is a space in key or "-" or there is a reserved word keyword need to add quotation marks.
3. The first letter of the constructor constructor must be capitalized
3.1 Constructor mode
function Person (name,age) {
This.name=name;
This.age=age;
This.todo=function () {
return this.age;
}
}
var person=new Person("",18); person.name; person[name]; 3.2 工厂模式 function person(name,age){ var obj=new Object(); obj.name=name; obj.age=age; return obj; } var p=person("冯宝宝",18); p.name 3.3 普通函数 function person(name){ //this==>指代函数的调用者 return name; } person("冯宝宝");4.构造函数与普通函数的区别 4.1 this 指向 构造函数的this指向创建的对象实例上 普遍函数指向函数的调用者 4.2 调用的方式 构造函数需要通过new调用 4.3 命名规则 构造函数第一个字母需要大写
function declarations and function expressions
function Add () {}
var add1=function () {}
Object-oriented in JavaScript