MCPcopy Index your code
hub / github.com/phaserjs/phaser / Class

Function Class

src/utils/Class.js:178–249  ·  view source on GitHub ↗

* `Phaser.Class` is the ES5-style class factory used throughout the Phaser framework to define * classes with prototype-based inheritance. It provides a consistent pattern for creating * classes and is the foundation on which most Phaser Game Objects and systems are built. * * Pass a plain objec

(definition)

Source from the content-addressed store, hash-verified

176 * });
177 */
178function Class (definition)
179{
180 if (!definition)
181 {
182 definition = {};
183 }
184
185 // The variable name here dictates what we see in Chrome debugger
186 var initialize;
187 var Extends;
188
189 if (definition.initialize)
190 {
191 if (typeof definition.initialize !== 'function')
192 {
193 throw new Error('initialize must be a function');
194 }
195
196 initialize = definition.initialize;
197
198 // Usually we should avoid 'delete' in V8 at all costs.
199 // However, its unlikely to make any performance difference
200 // here since we only call this on class creation (i.e. not object creation).
201 delete definition.initialize;
202 }
203 else if (definition.Extends)
204 {
205 var base = definition.Extends;
206
207 initialize = function ()
208 {
209 base.apply(this, arguments);
210 };
211 }
212 else
213 {
214 initialize = function () {};
215 }
216
217 if (definition.Extends)
218 {
219 initialize.prototype = Object.create(definition.Extends.prototype);
220 initialize.prototype.constructor = initialize;
221
222 // For getOwnPropertyDescriptor to work, we need to act directly on the Extends (or Mixin)
223
224 Extends = definition.Extends;
225
226 delete definition.Extends;
227 }
228 else
229 {
230 initialize.prototype.constructor = initialize;
231 }
232
233 // Grab the mixins, if they are specified...
234 var mixins = null;
235

Callers

nothing calls this directly

Calls 3

mixinFunction · 0.85
extendFunction · 0.70
createMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…