I have a property in my script and I want to add additional code to the setter.
I’m trying to extend the setter by replacing it with a new one and then call the original, but I’m a bit lost.
here is where I arrived so far:
var Text = pc.createScript('text');
Text.attributes.add('text', {
type: 'string',
default: '',
title: 'Text'
});
// initialize code called once per entity
Text.prototype.initialize = function() {
this.entity.element.text = this.text;
var self = this;
var textPropr = Object.getOwnPropertyDescriptor(this.__proto__, 'text');
Object.defineProperties(this.__proto__, 'text', { // <=== Exception here
get: function() { return textPropr.get.call(this); },
set: function(value) {
// update the text of the element
self.entity.element.text = value;
// force the children of the text element to be resized
self.entity.translateLocal(0, 0, 0);
// call original setter
textPropr.set.call(this, value);
}
});
};
Text.prototype.postInitialize = function() {
this.entity.element.text = this.text;
};
The exception I have is:
TypeError: Property description must be an object: t
at Function.defineProperties ()
at script.Text.initialize (Text.js?id=11035052:15)