寫es6時要增加Object的prototype 已經和以往的寫法大為不同了 所以就來介紹一下方法吧
// $.inArray 模擬 Array.includes
import $ from 'jquery';
if (!Array.prototype.includes) {
Object.defineProperty(Array.prototype, 'includes', {
value(...args) {
return $.inArray(...args, this) !== -1;
}
});
}
沒有留言:
張貼留言