Skip to content

Instantly share code, notes, and snippets.

@umayr
Created August 31, 2016 03:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save umayr/9e71f29d883443907e5c28ba0236cbcc to your computer and use it in GitHub Desktop.
Save umayr/9e71f29d883443907e5c28ba0236cbcc to your computer and use it in GitHub Desktop.
'use strict';
function log(type:string) {
return function(target: any, key: string, descriptor: PropertyDescriptor) {
let fn = descriptor.value;
descriptor.value = function(...args:any[]) {
console.log(`[${type.toLocaleUpperCase()}]: Invoking method - ${key}`);
let result = fn.apply(this, args);
console.log(`[${type.toLocaleUpperCase()}]: Completed method - ${key}`);
return result;
}
}
}
class Person {
name: string;
constructor(name: string) {
this.name = name;
}
@log('info')
sayHello(name?:string) : string {
return `Hello, ${name === '' ? 'world' : name}. I'm ${this.name}.`;
}
}
const namesTuple:[string, string][] = [['sulu', 'kirk'], ['sarah', 'john'], ['leia', 'luke']];
namesTuple.forEach(([own, their]) => {
let person = new Person(own);
console.log(person.sayHello(their));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment