静态对象: 不需要创建, 直接通过这个对象名字调用即可, (内置对象)
实例对象: 通过构造函数创建出来, 实例化的对象
Math.PI --->π
Math.abs(值)----> 取绝对值
Math.ceil(值) ---> 向上取整
Math.floor(值) ---> 向下取整
Math.round(值) ---> 四舍五入
Math.max(值1, 值2....) 取一堆数字的最大值
Math.min(值1, 值2....) 取一堆数字的最小值
Math.pow(值1, 值2) 次方
Math.sqrt(值1) 平方根
Math.random() 随机数 区间是 0-1
console.log(Math.ceil(4.1));//5
console.log(Math.floor(4.9));//4
console.log(Math.abs(-4.9));//4.9
console.log(Math.round(4.5));//5
console.log(Math.max(10,1, 50, 100));//100
console.log(Math.min(10,1, 50, 100));//1
console.log(Math.pow(2, 5));//次方
console.log(Math.sqrt(16));//平方根
取0-4的随机整数
console.log(Math.floor(Math.random()*5));
console.log(parseInt(Math.random()*5));
//自定义构造函数
function MyMath() {
//添加方法
this.getMax = function () {
console.log(arguments);
//假设一个最大值
var max = arguments[0];//获取实参的个数, 以伪数组的形式展示
for( var i = 0 ; i <arguments.length; i++){
if( max < arguments[i]){
max = arguments[i];
}
}
return max;
}
}
//实例化对象
var m = new MyMath();
console.log(m.getMax(10, 20, 100, 40, 50));