阅读目录:
- 1. 属性、方法、JS数据类型
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
一、创建对象
1、通过nwe关键字创建对象 var obj = new Object(); 2、对象字面量 1)简单字面量
var obj = {};
obj.name='测试';
obj.test = function(){
return this.name;
};
2)嵌套字面量 var obj = { name:'测试', test:function(){ console.log(this.name); } };
obj.test(); 函数申明和函数表达式 function test (){} var test = function(){} 3、构造函数(首字母必须大写) function Test(name,age){ this.name =name, this.age = age, this.todo = function(){ return this.name; } } var test = new Test('test',22);//实例化 test.todo();
javascript 六种数据类型:object、number、boolen、undefined、null、string,其中null代表“空值”,undefined表示声明了一个变量未初始化时,得到的就是undefined