javascript - Typescript Decorator, which overrwrites set of property -


im trying overwrite "set" of property decorator

decortaor:

function maxlength(maxlength: number) {     return function (target: object, key: string, descriptor: typedpropertydescriptor<string>) {         var oldset = descriptor.set;         descriptor.set = (value) => {             oldset.call(this, value);         }     } } 

decorated property:

private _entry: string = null; @maxlength(30) public entry(): string { return this._entry } public set entry(value: string) { this._entry = value } 

when " oldset.call(this, value)" gets called, "_entry"-field stays empty.

does know correct way overwrite "set"-mehtod?

in case, don't use arrow function.

currently this in oldset.call(this, value); equal global object—not instance of class. instead of assigning instance's property assigns window._entry.

change code instead use regular function, use function's this:

descriptor.set = function(value) {     oldset.call(this, value); }; 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -