MCPcopy Create free account
hub / github.com/phaserjs/phaser / extend

Function extend

src/utils/Class.js:79–119  ·  view source on GitHub ↗

* Extends the given `ctor` object's prototype with the properties of `definition`. * * @function extend * @ignore * @param {Object} ctor The constructor object to mix into. * @param {Object} definition A dictionary of functions for the class. * @param {boolean} isClassDescriptor Is the definit

(ctor, definition, isClassDescriptor, extend)

Source from the content-addressed store, hash-verified

77 * @param {Object} [extend] The parent constructor object.
78 */
79function extend (ctor, definition, isClassDescriptor, extend)
80{
81 for (var k in definition)
82 {
83 if (!definition.hasOwnProperty(k))
84 {
85 continue;
86 }
87
88 var def = getProperty(definition, k, isClassDescriptor);
89
90 if (def !== false)
91 {
92 // If Extends is used, we will check its prototype to see if the final variable exists.
93
94 var parent = extend || ctor;
95
96 if (hasNonConfigurable(parent.prototype, k))
97 {
98 // Just skip the final property
99 if (Class.ignoreFinals)
100 {
101 continue;
102 }
103
104 // We cannot re-define a property that is configurable=false.
105 // So we will consider them final and throw an error. This is by
106 // default so it is clear to the developer what is happening.
107 // You can set ignoreFinals to true if you need to extend a class
108 // which has configurable=false; it will simply not re-define final properties.
109 throw new Error('cannot override final property \'' + k + '\', set Class.ignoreFinals = true to skip');
110 }
111
112 Object.defineProperty(ctor.prototype, k, def);
113 }
114 else
115 {
116 ctor.prototype[k] = definition[k];
117 }
118 }
119}
120
121/**
122 * Applies the given `mixins` to the prototype of `myClass`.

Callers 2

mixinFunction · 0.70
ClassFunction · 0.70

Calls 2

getPropertyFunction · 0.85
hasNonConfigurableFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…