Created
August 31, 2016 03:24
-
-
Save umayr/9e71f29d883443907e5c28ba0236cbcc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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