Created
October 7, 2013 14:14
-
-
Save marceloxp/6868711 to your computer and use it in GitHub Desktop.
JavaScript isset()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isset () { | |
// http://kevin.vanzonneveld.net | |
// + 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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment