您的位置:首页 > Web前端 > JavaScript

js计算点到原点的距离

2014-09-22 13:27 232 查看
假设为1,1

<script type="text/javascript">
	function Point(x,y){
		this.x = x;
		this.y = y;
	}
	
	var p = new Point(1,1);
	
	Point.prototype.r = function(){
		return Math.sqrt(
			this.x*this.x+this.y*this.y		
		);
	};
	
	alert(p.r());
</script>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐