diff options
Diffstat (limited to 'src/types')
-rw-r--r-- | src/types/List.js | 38 | ||||
-rw-r--r-- | src/types/set.js | 18 |
2 files changed, 38 insertions, 18 deletions
diff --git a/src/types/List.js b/src/types/List.js new file mode 100644 index 0000000..f3c0e1e --- /dev/null +++ b/src/types/List.js @@ -0,0 +1,38 @@ +import { extend } from '../utils/adopter.js' +import { subClassArray } from './ArrayPolyfill.js' + +const List = subClassArray('List', Array, function (arr) { + this.length = 0 + this.push(...arr) +}) + +export default List + +extend(List, { + each (cbOrName, ...args) { + if (typeof cbOrName === 'function') { + this.forEach((el) => { cbOrName.call(el, el) }) + } else { + this.forEach((el) => { + el[cbOrName](...args) + }) + } + + return this + }, + + toArray () { + return Array.prototype.concat.apply([], this) + } +}) + +List.extend = function (methods) { + methods = methods.reduce((obj, name) => { + obj[name] = function (...attrs) { + return this.each(name, ...attrs) + } + return obj + }, {}) + + extend(List, methods) +} diff --git a/src/types/set.js b/src/types/set.js deleted file mode 100644 index c755c2c..0000000 --- a/src/types/set.js +++ /dev/null @@ -1,18 +0,0 @@ -/* eslint no-unused-vars: "off" */ -class SVGSet extends Set { - // constructor (arr) { - // super(arr) - // } - - each (cbOrName, ...args) { - if (typeof cbOrName === 'function') { - this.forEach((el) => { cbOrName.call(el, el) }) - } else { - this.forEach((el) => { - el[cbOrName](...args) - }) - } - - return this - } -} |