View: method_exists

Function:
Description: Checks if the class method exists.
Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
function method_exists (obj, method) {
    // http://jsphp.co/jsphp/fn/view/method_exists
    // +   original by: Brett Zamir (http://brett-zamir.me)
    // *     example 1: function class_a() {this.meth1 = function () {return true;}};
    // *     example 1: var instance_a = new class_a();
    // *     example 1: method_exists(instance_a, 'meth1');
    // *     returns 1: true
    // *     example 2: function class_a() {this.meth1 = function () {return true;}};
    // *     example 2: var instance_a = new class_a();
    // *     example 2: method_exists(instance_a, 'meth2');
    // *     returns 2: false
    if (typeof obj === 'string') {
        return this.window[obj] && typeof this.window[obj][method] === 'function';
    }

    return typeof obj[method] === 'function';
}
Comment on method_exists version 102
Tests
Benchmark
[top]

Comments

There are no comments yet, be the first!

Please Login or Register to post comments.