constructor(properties) { if (!wasApplied) { Class.proto(); // prepare prototype... } let self = this; if (initFactory !== void 0) { FACTORY_FOR.set(this, initFactory); initFactory = void 0; } let beforeInitCalled; // only used in debug builds to enable the proxy trap // using DEBUG here to avoid the extraneous variable when not needed if (DEBUG) { beforeInitCalled = true; } if (DEBUG && HAS_NATIVE_PROXY && typeof self.unknownProperty === 'function') { let messageFor = (obj, property) => { return ( `You attempted to access the \`${String(property)}\` property (of ${obj}).\n` + `Since Ember 3.1, this is usually fine as you no longer need to use \`.get()\`\n` + `to access computed properties. However, in this case, the object in question\n` + `is a special kind of Ember object (a proxy). Therefore, it is still necessary\n` + `to use \`.get('${String(property)}')\` in this case.\n\n` + `If you encountered this error because of third-party code that you don't control,\n` + `there is more information at https://github.com/emberjs/ember.js/issues/16148, and\n` + `you can help us improve this error message by telling us more about what happened in\n` + `this situation.` ); }; /* globals Proxy Reflect */ self = new Proxy(this, { get(target, property, receiver) { if (property === PROXY_CONTENT) { return target; } else if ( beforeInitCalled || typeof property === 'symbol' || isInternalSymbol(property) || property === 'toJSON' || property === 'toString' || property === 'toStringExtension' || property === 'didDefineProperty' || property === 'willWatchProperty' || property === 'didUnwatchProperty' || property === 'didAddListener' || property === 'didRemoveListener' || property === 'isDescriptor' || property === '_onLookup' || property in target ) { return Reflect.get(target, property, receiver); } let value = target.unknownProperty.call(receiver, property); if (typeof value !== 'function') { assert(messageFor(receiver, property), value === undefined || value === null); } }, }); FACTORY_FOR.set(self, FACTORY_FOR.get(this)); } let m = meta(self); let proto = m.proto; m.proto = self; if (properties !== undefined) { assert( 'EmberObject.create only accepts objects.', typeof properties === 'object' && properties !== null ); assert( 'EmberObject.create no longer supports mixing in other ' + 'definitions, use .extend & .create separately instead.', !(properties instanceof Mixin) ); let concatenatedProperties = self.concatenatedProperties; let mergedProperties = self.mergedProperties; let hasConcatenatedProps = concatenatedProperties !== undefined && concatenatedProperties.length > 0; let hasMergedProps = mergedProperties !== undefined && mergedProperties.length > 0; let keyNames = Object.keys(properties); for (let i = 0; i < keyNames.length; i++) { let keyName = keyNames[i]; let value = properties[keyName]; if (BINDING_SUPPORT && ENV._ENABLE_BINDING_SUPPORT && Mixin.detectBinding(keyName)) { m.writeBindings(keyName, value); } assert( 'EmberObject.create no longer supports defining computed ' + 'properties. Define computed properties using extend() or reopen() ' + 'before calling create().', !(value instanceof ComputedProperty) ); assert( 'EmberObject.create no longer supports defining methods that call _super.', !(typeof value === 'function' && value.toString().indexOf('._super') !== -1) ); assert( '`actions` must be provided at extend time, not at create time, ' + 'when Ember.ActionHandler is used (i.e. views, controllers & routes).', !(keyName === 'actions' && ActionHandler.detect(this)) ); let possibleDesc = descriptorFor(self, keyName, m); let isDescriptor = possibleDesc !== undefined; if (!isDescriptor) { let baseValue = self[keyName]; if (hasConcatenatedProps && concatenatedProperties.indexOf(keyName) > -1) { if (baseValue) { value = makeArray(baseValue).concat(value); } else { value = makeArray(value); } } if (hasMergedProps && mergedProperties.indexOf(keyName) > -1) { value = assign({}, baseValue, value); } } if (isDescriptor) { possibleDesc.set(self, keyName, value); } else if (typeof self.setUnknownProperty === 'function' && !(keyName in self)) { self.setUnknownProperty(keyName, value); } else { if (DEBUG) { defineProperty(self, keyName, null, value); // setup mandatory setter } else { self[keyName] = value; } } } } if (BINDING_SUPPORT && ENV._ENABLE_BINDING_SUPPORT) { Mixin.finishPartial(self, m); } // using DEBUG here to avoid the extraneous variable when not needed if (DEBUG) { beforeInitCalled = false; } self.init(...arguments); m.proto = proto; finishChains(m); sendEvent(self, 'init', undefined, undefined, undefined, m); // only return when in debug builds and `self` is the proxy created above if (DEBUG && self !== this) { return self; } }
return this.get('fullName'); } }); teacher = Teacher.create(); teacher.toString(); //=> "<Teacher:ember1026:Tom Dale>" ``` @method toString @return {String} string representation @public */ toString() { let hasToStringExtension = typeof this.toStringExtension === 'function'; let extension = hasToStringExtension ? `:${this.toStringExtension()}` : ''; let ret = `<${this[NAME_KEY] || FACTORY_FOR.get(this) || this.constructor.toString()}:${guidFor(this)}${extension}>`; return ret; } }); CoreObject.PrototypeMixin.ownerConstructor = CoreObject; CoreObject.__super__ = null; let ClassMixinProps = { isClass: true, isMethod: false, [NAME_KEY]: null,
return this.get('fullName'); } }); teacher = Teacher.create(); teacher.toString(); //=> "<Teacher:ember1026:Tom Dale>" ``` @method toString @return {String} string representation @public */ toString() { let hasToStringExtension = typeof this.toStringExtension === 'function'; let extension = hasToStringExtension ? `:${this.toStringExtension()}` : ''; let ret = `<${getName(this) || FACTORY_FOR.get(this) || this.constructor.toString()}:${guidFor( this )}${extension}>`; return ret; }, }); CoreObject.PrototypeMixin.ownerConstructor = CoreObject; CoreObject.__super__ = null; let ClassMixinProps = { isClass: true, isMethod: false,
/** `EmberObject` is the main base class for all Ember objects. It is a subclass of `CoreObject` with the `Observable` mixin applied. For details, see the documentation for each of these. @class EmberObject @extends CoreObject @uses Observable @public */ const EmberObject = CoreObject.extend(Observable, { _debugContainerKey: descriptor({ enumerable: false, get() { let factory = FACTORY_FOR.get(this); return factory !== undefined && factory.fullName; }, }), [OWNER]: descriptor({ enumerable: false, get() { if (this[OVERRIDE_OWNER]) { return this[OVERRIDE_OWNER]; } let factory = FACTORY_FOR.get(this); return factory !== undefined && factory.owner;