- call:
- 格式:父类.call(子类实例,参数1,参数2,参数3...)
- apply:
格式:父类.apply(子类实例,[参数1,参数2,参数3...])
实例后面为数组
call案例:
<button>按钮1</button>
<button>按钮2</button>
<button>按钮3</button>
<button>按钮4</button>
<button>按钮5</button>
<script>
//得到每一个button的innerText
const btns = document.querySelectorAll('button');
const result = Array.prototype.map.call(btns,function(item){
return item.innerText;
})
</script>
apply案例:
let nums = [10,20,10,60,35,115,64,87,14];
const result = Math.max.apply(null,nums);
判断数据类型:
- typeof
- Array.isArray()
- isNaN()
- jQuery.type()
- Object.prototype.toString()
function type(data){
return Object.prototype.toString.call(data).slice(8,-1).toLowerCase();
}