码迷,mamicode.com
首页 > 编程语言 > 详细

JavaScript内置对象Math查询一组数中的最大值

时间:2018-07-16 23:04:52      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:实现   nts   script   this   for   查找   mat   cti   arguments   

//查找一组数据中的最大值
var result = Math.max(10, 20, 39, 40);
alert(result);

//自定义一个对象,实现系统方法max的方法
function MyMath() {
//添加了一个方法
this.getMax = function () {
var max = arguments[0];
for (var i = 0; i < arguments.length; i++) {
if (arguments[i] > max) {
max = arguments[i];
}
}
return max;
};
}
//实例对象
var mt = new MyMath();
var result1 = mt.getMax(1, 3, 6, 9, 2, 6, 3);
alert(result1);

JavaScript内置对象Math查询一组数中的最大值

标签:实现   nts   script   this   for   查找   mat   cti   arguments   

原文地址:https://www.cnblogs.com/cuilichao/p/9320752.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!