Function: classkit_method_rename version 109

Function:
Description: Dynamically changes the name of the given method.
Version:
Status: latest
Date: 2011-12-20 05:23
Summary: Import from phpjs.
Programmer: jj5
Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
function classkit_method_rename (classname, methodname, newname) {
    // http://jsphp.co/jsphp/fn/view/classkit_method_rename
    // +   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;
}
[top]

Comments

There are no comments yet, be the first!

Please Login or Register to post comments.