[Javascript]几个小测试

  • 指出有错误的语句,并解释为什么。
1 var dom = function () {};
2 dom.Show = function () {alert('Show Message');};
3 dom.prototype.Display = function () {alert('Property Message');};
4 
5 dom.Display();
6 dom.Show();
7 var d = new dom();
8 d.Display();
9 d.Show();
  • 如何调用say方法,并给出输出结果。
 1 var a = {
 2   b: function () {
 3     this.say = function () {alert('say hello!');};
 4     alert("I'm b");
 5   }
 6 };
  •  给出结果,并解释为什么,用到了什么技术。
 1 function counter() {
 2     var n = 0;
 3     return {
 4         count: function() {return n++;},
 5         reset: function() {n = 0;}
 6     };
 7 }
 8 
 9 var x = counter(), y = counter();
10 console.log(x.count());
11 console.log(x.count());
12 console.log(y.count());

 

posted on 2015-03-27 13:41  eulerlcs  阅读(151)  评论(0)    收藏  举报

导航