<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>index</title> <meta name="author" content="Administrator" /> <script type="text/javascript" src="yuan.js"></script> <!-- Date: 2015-12-29 --> <script type="text/javascript"> var r = 5; var circle = new Circle(r); document.write("半径为"+r+"的周长:"+circle.perimeter()+",面积:"+ circle.area()); </script> </head> <body> </body></html>yuan.js文件代码:
/** * 创建一个对象圆 * 属性:半径 * 方法:面积和周长 * @author Administrator */function Circle(r){ this.r = r;}Circle.prototype.area = function(){ return this.r * this.r;};Circle.prototype.perimeter = function(){ return 2 * Math.PI * this.r;};
版权声明
本文仅代表作者观点,不代表百度立场。
本文系作者授权百度百家发表,未经许可,不得转载。



