Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Kayıt işlemleri için kullandığımız sınıfımız
- */
- class Logger{
- log(message){
- console.log(message);
- }
- }
- let logger = new Logger();
- /**
- * Kayıt almak için kullandığımız decorator sınıfımız
- */
- function log(message){
- return function (target,propertyKey, descriptor){
- let orginalFn = descriptor.value;
- descriptor.value = function (){
- let logMessage = message;
- for(let i in arguments){
- logMessage = logMessage.replace('{'+i+'}',arguments[i]);
- }
- logger.log(logMessage);
- orginalFn.apply(this,arguments);
- }
- }
- }
- /**
- * Kullanıcı işlemlerinden sorumlu sınıfımız
- */
- class User{
- @log('{0} adlı kullanıcı oluşturuluyor.')
- create(name){
- console.log(name+" adlı kullanıcı oluşturuldu.");
- }
- @log('{0} adlı kullanıcı siliniyor.')
- delete(name){
- console.log(name +" adlı kullanıcı silindi.");
- }
- }
- var user = new User();
- user.create('hakan');
- /**
- * hakan adlı kullanıcı oluşturuluyor.
- * hakan adlı kullanıcı oluşturuldu.
- */
- user.delete('hakan');
- /**
- * hakan adlı kullanıcı siliniyor.
- * hakan adlı kullanıcı silindi.
- */
Add Comment
Please, Sign In to add comment