1.如果要打开名为 “window2"的新窗口,可以通过()
window.open("http://www.w3school.com.cn","window2")
解析:window.open()方法是用指定的名称将指定的资源加载到浏览器上下文中,第一个参数是url,第二个参数是名称。
2.下面这段JavaScript代码的的输出是什么?
var myObject = {
foo: "bar",
func: function() {
var self = this;
console.log(this.foo); //"bar"
console.log(self.foo); //"bar"
(function() {
console.log(this.foo); //undefined
console.log(self.foo); //"bar"
}());
}
};
myObject.func();
解析:第一行 this.foo 中 this指向myObject对象,结果是"foo";
第二行 self.foo 中 self是 this指向myObject对象,结果是"foo";
第三行 this.foo 中,因为是IIFE(立即执行函数),所以this指向window,结果是undefine