严格模式下:
1,不允许使用with语句;
2,不允许给未声明的变量赋值;
3,arguments,是与形参不同的变量副本;
4,delete不允许被删除的变量会报错,而不是返回false;
5,不允许重复的对象字面量属性名;
6,不允许八进制的字面量;
7,eval, arguments成为关键词,不允许用来作为变量名和函数名;
8,eval()会单独创建一个作用域,并在eval()返回时丢弃;
1,不允许使用with语句;
2,不允许给未声明的变量赋值;
3,arguments,是与形参不同的变量副本;
4,delete不允许被删除的变量会报错,而不是返回false;
5,不允许重复的对象字面量属性名;
6,不允许八进制的字面量;
7,eval, arguments成为关键词,不允许用来作为变量名和函数名;
8,eval()会单独创建一个作用域,并在eval()返回时丢弃;
2018-04-20
//枚举对象自身的非函数属性(不包括原型链中的属性)
for(var k in o){
if(o.hasOwnProperty(k)) && typeof k !== 'function'){
//do whatever you want to do (为所欲为)
}
}
for(var k in o){
if(o.hasOwnProperty(k)) && typeof k !== 'function'){
//do whatever you want to do (为所欲为)
}
}
2018-04-20
try{
//throw a Exception
}catch(e){
//catch the Exception and process it
}finally{
//do something to end
}
//throw a Exception
}catch(e){
//catch the Exception and process it
}finally{
//do something to end
}
2018-04-20
s.hasOwnProperty('name'); //true
s.hasOwnProperty('major'); //false
s.__proto__.hasOwnProperty('major'); //true
Student.hasOwnProperty('name'); //true
Student.hasOwnProperty('major'); //false
Student.prototype.hasOwnProperty('major'); //true
s.hasOwnProperty('major'); //false
s.__proto__.hasOwnProperty('major'); //true
Student.hasOwnProperty('name'); //true
Student.hasOwnProperty('major'); //false
Student.prototype.hasOwnProperty('major'); //true
2018-04-20
function Person(){this.name = 'Bosn'; }
function Student(){this.major ='IT';}
Student.prototype = new Person();
Student.prototype.constructor = Student;
var s = new Student();
function Student(){this.major ='IT';}
Student.prototype = new Person();
Student.prototype.constructor = Student;
var s = new Student();
2018-04-20
var a = {};
Object.defineProperty(a, 'x', {value: 1});
通过Object.defineProperty()为对象添加属性时,属性默认是不可删除、不可改写、不可枚举的。
可以通过Object.getOwnPropertyDescriptor(a, 'x')来查看。
Object.defineProperty(a, 'x', {value: 1});
通过Object.defineProperty()为对象添加属性时,属性默认是不可删除、不可改写、不可枚举的。
可以通过Object.getOwnPropertyDescriptor(a, 'x')来查看。
2018-04-20
function getType(e){
if(typeof e !== 'object') return typeof e;
if(e instanceof 'Array') return 'array';
if(e instanceof 'Date') return 'date';
if(e instanceof 'window') return 'window';
if(e instanceof 'RegExp') return 'regexp';
return 'otherType';
}
if(typeof e !== 'object') return typeof e;
if(e instanceof 'Array') return 'array';
if(e instanceof 'Date') return 'date';
if(e instanceof 'window') return 'window';
if(e instanceof 'RegExp') return 'regexp';
return 'otherType';
}
duck type '刘德华' == false;
duck type '鹿晗' == true;
duck type '吴亦凡' == true;
duck type '鹿晗' == true;
duck type '吴亦凡' == true;
2018-04-20
NaN == NaN; //false
new Object() == new Object(); //false
{} == {}; //false
"我爱言承旭" == true; //true
new Object() == new Object(); //false
{} == {}; //false
"我爱言承旭" == true; //true
2018-04-20
javaScript一共有六种数据类型:
1、五种基本类型:
boolean, number, string, undefined, null;
2、一种复合类型--对象:
Object
注:其他复合类型都继承自Object类型,如Array, Date, RegExp, Function, etc;
1、五种基本类型:
boolean, number, string, undefined, null;
2、一种复合类型--对象:
Object
注:其他复合类型都继承自Object类型,如Array, Date, RegExp, Function, etc;
2018-04-20