标签:
4种。
1.function circleArea(r) { this.r = r; this.area = function() { console.log(‘第一种:‘+Math.PI * this.r * this.r) ; }; } //测试 var ct= new circleArea(1.5); ct.area();
2.function circleArea(r){ this.r = r; } circleArea.prototype.area = function () { console.log(‘第二种:‘+Math.PI * this.r * this.r) ; }; //测试 var ct = new circleArea(2.5); ct.area();
3.var circleArea = { r : 1, area : function() { console.log(‘第三种:‘+Math.PI*this.r*this.r) } }; //测试 circleArea.r = 6; circleArea.area();
4.var circleArea = {}; circleArea.r = 5; circleArea.area = function() { console.log(‘第四种:‘+Math.PI*this.r*this.r); }; //测试 circleArea.area();
标签:
原文地址:http://www.cnblogs.com/camillea/p/js_oobway.html