@lopatnov/make-iterable

node v10.24.1
version: 1.3.1
endpointsharetweet
var makeIterable = require("@lopatnov/make-iterable")
let x = { hello: "world" }; let iterableX = makeIterable(x); iterableX.push(10); iterableX.push(20); iterableX.push(30); iterableX.push(40); iterableX.pop(); console.log(`x === iterableX ? ${x === iterableX}`); // true console.log(`indexOf(30) = ${iterableX.indexOf(30)}`); // 2 console.log(`[...iterableX] = ${[...iterableX]}`); // [10,20,30] console.log(`iterableX.hello = ${iterableX.hello}`); // "world"
class Sample { constructor(message) { Sample.count++; this.message = message; } } Sample.count = 0; makeIterable(Sample.prototype); let q = new Sample("Hello world"); // makes array-like object let t = new Sample("It working!"); // makes array-like object q.push(true, false, true, true, false, true, false, true); t.push("hello", "world", "!"); console.log(Sample.count); // 2 console.log([...q]); // true, false, true, true, false, true, false, true console.log([...t]); // "hello", "world", "!" console.log(q.message); // Hello world console.log(t.message); // It working!
Loading…

no comments

    sign in to comment