新开传奇网站一,西安网站建设的软件,如何做好企业网站建设工作,visual c 网站开发链式调用
在每个函数内部return this
访问对象属性
点语法[]中括号内是字符串或是变量 数组是特殊的对象 对象属性遍历
for in(遍历对象或数组) - 不必再用Object.keys那么麻烦了
for(var key in obj){console.log(obj[key])// obj.key返回undefined// 因为js引擎会转换为…链式调用
在每个函数内部return this
访问对象属性
点语法[]中括号内是字符串或是变量 数组是特殊的对象 对象属性遍历
for in(遍历对象或数组) - 不必再用Object.keys那么麻烦了
for(var key in obj){console.log(obj[key])// obj.key返回undefined// 因为js引擎会转换为obj[key]
}instanceof
console.log([] instanceof Array) // true
console.log([] instanceof Object) // true
console.log({} instanceof Object) // true类型判断
var a [] || {}
console.log(a.constructor)
console.log(a instanceof Array)
console.log(Object.prototype.toString.call(a))
// 实际运用时先缓存 var strFn Object.prototype.toString// Object.prototype {
// toString:function(){
// this.toString() // this → a
// }
// }函数内部的this
只要没有实例化构造函数函数内部的this指向window全局范围的this指向window构造函数内this指向
arguments.callee - 正在被执行的函数对象
function test(a, b, c, d) {console.log(arguments.callee.length)
}
test() // 4应用在自启动函数中使用递归且不需要函数名
var res (function (n) {if (n 1) {return 1}return n n arguments.callee(n - 1)
})(10);
console.log(res) // 55caller - 当前函数的调用者
严格模式下使用arguments、callee、caller会报错
dad()
function dad() {child()
}
function child() {console.log(child的调用者, child.caller)
}练习 typeof的返回值有几种6种如何不用isNaN判断NaN(转换成字符串) 引用值对比的是地址这个是比较不是隐式类型转换 函数test的AO有a
apply、call传nullthis指向是什么
function Test(name) {this.name name
}
function Test2() {Test.call(null, 测试)
}
console.log(obj, new Test2())