几道题
1. 下面代码alert的内容
function tr42(){ var a2, b2; a2 = {"c": 1}; b2 = a2; a2.c = 2; alert(b2.c); a2 = {"c": 3}; alert(b2.c); a2.c = 4; alert(b2.c); } tr42();
2. 下面代码alert的内容
function tc51(){ var a2 = 6; window.setTimeout((function(){ alert(a2); a2 = 666; }), 1000); a2 = 66; window.setTimeout((function(){ alert(a2); }), 3000); } tc51();
3.请阐述 代码的功能,代码的优点和缺点. listener.apply(el)在此处的作用. 如果有可改进之处,请给出改进后的代码,并说明理由。
if (window.addEventListener) { var addListener = function(el, type, listener, useCapture){ el.addEventListener(type, listener, useCapture); }; } else if (document.all) { addListener = function(el, type, listener){ el.attachEvent("on" + type, function(){ listener.apply(el); }); }; }
4. 下面代码alert的内容
function ts61(){ try { i = 2; throw Error("error message!"); } catch (err) { var i = 1; alert(err.message); } alert(i); alert(window.i); alert(window.err); alert(err.message); } ts61();
5. 最后三行 问号处分别可以填哪些值让表达式成立.
function to62(){ function Person(name, age){ this.name = name; this.age = age; this.getName = function(){ alert(this.name); }; } Person.prototype = { getAge: function(){ alert(this.age); } }; var p = new Person("bob", "21"); P instanceof ? == true p.constructor == ? p.hasOwnProterty(?) == true } to62();
6. 简述如何各种浏览器内得到DomReady事件(写要点即可)