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

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -

javascript - Restarting Supervisor and effect on FlaskSocketIO -

php - Mongodb connectivity error -