本人的面试踩坑,持续更新......
1.构造函数里定义变量,外部不能访问
2.hasOwnProperty()只能检测自身属性,继承的属性跟方法并不能检测。
function Fun(a,b){
this.a = a;
this.b = b;
var c = 3; //这里定义变量无效
}
Fun.prototype.sum = function(){return this.a + this.b}
var fun = new Fun(1,2)
console.log(fun.c); //undefinded
console.log(fun.hasOwnProperty("sum")) //false
3.array.sort()默认是按照 ASCII 排序的,因此
升序:
arr.sort(function(a,b){
return a-b;
})
降序:
arr.sort(function(a,b){
return b-a;
})