php isset() equivalent in javascript

后端 未结 3 1134
后悔当初
后悔当初 2021-01-06 02:32

I\'m looking for the javascript equivalent of the php function isset(). I\'ve tried the method described here at JavaScript isset() equivalent but at firebug, e

3条回答
  •  青春惊慌失措
    2021-01-06 03:15

    I think the best solution is to look in the source code of php.js:

    function isset () {
        // !No description available for isset. @php.js developers: Please update the function summary text file.
        // 
        // version: 1103.1210
        // discuss at: http://phpjs.org/functions/isset
        // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
        // +   improved by: FremyCompany
        // +   improved by: Onno Marsman
        // +   improved by: Rafał Kukawski
        // *     example 1: isset( undefined, true);
        // *     returns 1: false
        // *     example 2: isset( 'Kevin van Zonneveld' );
        // *     returns 2: true
        var a = arguments,
            l = a.length,
            i = 0,
            undef;
    
        if (l === 0) {
            throw new Error('Empty isset');
        }
    
        while (i !== l) {
            if (a[i] === undef || a[i] === null) {
                return false;
            }
            i++;
        }
        return true;
    }
    

提交回复
热议问题