JavaScript classkit_method_rename function

A JavaScript equivalent of PHP’s classkit_method_rename
function classkit_method_rename (classname, methodname, newname) {
  // http://kevin.vanzonneveld.net
  // +   original by: Brett Zamir (http://brett-zamir.me)
  // *     example 1: classkit_method_rename('someClass', 'someMethod', 'newMethod');
  // *     returns 1: true

  if (typeof classname === 'string') {
    classname = this.window[classname];
  }

/*
  var method = classname[methodname]; // Static
  classname[newname] = method;
  delete classname[methodname];
  */

  var method = classname.prototype[methodname];
  classname.prototype[newname] = method;
  delete classname.prototype[methodname];

  return true;
}

Example 1
classkit_method_rename('someClass', 'someMethod', 'newMethod');

Should return
true
Теги:
classkit_method_rename
Добавлено: 25 Июля 2018 19:33:16 Добавил: Андрей Ковальчук Нравится 0
Добавить
Комментарии:
Нету комментариев для вывода...