how to achieve the max

How to achieve the max

手写字符串trim方法,保证浏览器兼容性

如何获取多个数字中的最大值

手写字符串trim保证浏览器兼容性

String.prototype.trim = function (){
    return this.replace(/^\s+/,'').replace(/\s+$/,'')
}
//(原型,this,正则表达式 命中从开头开始的空白字符,替换为空字符串,和结尾靠近的空白字符命中,用空字符串替换掉)

如何获取多个数字中的最大值

function max(){
    const nums = Array.prototype.slice.call(arguments)
    let max =0
    nums.forEach(n=>{
        if(n>max){
            max=n
        }
    })
    return max
}

 Math.max(10,20,30,50,40,80)

 Math.min(10,20,30,50,40,80)

如何用JS实现继承

class继承

prototype 继承