title: Creating a property getter and setter with TypeScript Decorator
body: <p>I want to create a property getter and setter with TypeScript Decorator but I'm stuck on defining the function to run when the property is changed or requested.</p>
  
  <p>If I have the following usage of my <code>Field.watch</code> decorator:</p>
  
  <pre><code>export class Test {
     ...
     @Field.watch({onSet: this.resetCssCache})
     public layoutId = 0;
     ...
     public resetCssCache() {
        ...
     }
     ...
  }
  </code></pre>
  
  <p>and the decorator implementation is:</p>
  
  <pre><code>export class Field {
  
      public static watch(watchers: { onGet?: () =&gt; any, onSet?: (newValue: any, oldValue: any) =&gt; any }): Function {
          return (target: any, key: string) =&gt; {
  
              // property getter
              const getter = function() {
                  return this['_' + key];
              };
  
              // property setter
              const setter = function(newVal) {
                  if (watchers.onSet) {
                      this['_' + key] = watchers.onSet(newVal, this['_' + key]);
                  }
                  this['_' + key] = newVal;
              };
  
              // Delete property.
              if (delete this[key]) {
  
                  // Create new property with getter and setter
                  Object.defineProperty(target, key, {
                      get: getter,
                      set: setter,
                      enumerable: true,
                      configurable: true
                  });
              }
          }
      }
  }
  </code></pre>
  
  <p>I get an error on <code>@Field.watch({onSet: this.resetCssCache})</code> telling that <code>this</code> is not defined.</p>
  
  <p>I guess the decorator is interpreted on definition level and not on instance level. 
  Is there a way to bind a non-static method to the onSet propery of my decorator?</p>