javascript prototype 的简单用法

 1 /*
 2 function Box() {
 3     this.a = [];
 4   this.fn = function() {}
 5 }
 6 
 7 var box1 = new Box();
 8 var box2 = new Box();
 9 box1.a.push(1);
10 box1.a.push(2);
11 box1.fn = {};
12 
13 console.log(
14     box1.a,
15   box1.fn,
16   box2.a,
17   box2.fn
18 );
19 */
20 
21 var Browser = function() {};
22 Browser.prototype = {
23     run: function() {
24       alert("I'm Gecko,a kernel of firebox");
25   },
26   back: function() {
27       alert('exit');
28   }
29 }
30 /*
31 Browser.prototype.run = function() {
32     alert("I'm Gecko,a kernel of firebox");
33 }
34 */
35 var Bro = new Browser();
36 Bro.back();

 

posted @ 2016-02-16 10:55  bronana  阅读(183)  评论(0编辑  收藏  举报