👔Object+arrayLike
JS ⟩ object ⟩ built-in ⟩ Array ⟩ array-like ⟩ Object+arrayLike
extend array-like objects with custom methods.
- TouchList+ext - TouchList is an array-like. 
💾 replit:Object+arrayLike
// 2023.01.17 - 07:57 - first draft
// --------------------------------------------------
// helpers
function checkType(obj) {
    if (!('length' in obj)) {
        throw Error(`${obj} is not an "array-like" object!`)
    }
}
// ⭐️ Object + array-like
// --------------------------------------------------
// 🔹 .map()
//
Object.defineProperties(Object.prototype, {
    // 🔹 .map()
    map: {
        value: function(f) {
            checkType(this);
            const arr = [];
            for (let i = 0; i < this.length; i++) {
                arr.push(f(this[i]));
            }
            return arr;
        }
    },
    
});
// export 
// -------------------------------------------
export {};              // ES module
// module.exports = {};    // CommonJS moduleLast updated
Was this helpful?