(self, { include, exclude } = {})
| 98 | `; |
| 99 | |
| 100 | function AutoBind(self, { include, exclude } = {}) { |
| 101 | const getAllProperties = object => { |
| 102 | const properties = new Set(); |
| 103 | do { |
| 104 | for (const key of Reflect.ownKeys(object)) { |
| 105 | properties.add([object, key]); |
| 106 | } |
| 107 | } while ((object = Reflect.getPrototypeOf(object)) && object !== Object.prototype); |
| 108 | return properties; |
| 109 | }; |
| 110 | |
| 111 | const filter = key => { |
| 112 | const match = pattern => (typeof pattern === 'string' ? key === pattern : pattern.test(key)); |
| 113 | |
| 114 | if (include) return include.some(match); |
| 115 | if (exclude) return !exclude.some(match); |
| 116 | return true; |
| 117 | }; |
| 118 | |
| 119 | for (const [object, key] of getAllProperties(self.constructor.prototype)) { |
| 120 | if (key === 'constructor' || !filter(key)) continue; |
| 121 | const descriptor = Reflect.getOwnPropertyDescriptor(object, key); |
| 122 | if (descriptor && typeof descriptor.value === 'function') { |
| 123 | self[key] = self[key].bind(self); |
| 124 | } |
| 125 | } |
| 126 | return self; |
| 127 | } |
| 128 | |
| 129 | function lerp(p1, p2, t) { |
| 130 | return p1 + (p2 - p1) * t; |
no test coverage detected