JS对象、包装类
属性的增、删、改、查
增加属性:ojb.newProp = “what";
删除属性:delete ojb.Prop
对象的创建方法
- var obj = {} plainObject 对象字面量/对象直接量
- 构造函数
1)系统自带的构造函数 new Object()
2)自定义构造函数。
构造函数结构上和函数没有任何区别:java ?function person(name,sge){ ?????//this = {}; ?????this.name = name;//属性 ?????this.age = age; ?????this.study = function(){ ?????????函数体 ?????}//方法 ?????//return this; ?} ?var person1 = new person(name,age);
构造函数内部原理:
1.在函数体前面隐式地加上this={};
2.执行this.xxx=xxx;
3.隐式地返回this。
包装类
原始值不能有属性和方法,当给它们添加属性的时候系统会自动进行包装类并销毁。
var num = new Number(3);var str = new String("chen");var num = 3;num.len = 2;//new Number(3).len =2; deleteconsole.log(num.len);//endefinedvar str = "abcd";str.length = 2;//new String(‘abcd).length = 2; delete;console.log(str);//abcd//new String(‘abcd).length//.length是string系统自带的属性。console.log(str.length);//4
JS对象、包装类
原文地址:https://www.cnblogs.com/chenyingjie1207/p/9966039.html