Deprecated
Usage
nebula.has(obj, prop)
Parameters
obj
(Required) (Object) The object name to look into
Default: None
prop
(Required) (String) The property too look for
Default: None
Parameter Notes
Important: pass prop as a string with object notation (period separated).
Examples
The main benefit of using this function is that it handles nested objects with a single call
if ( nebula.has(nebula, 'user.client.remote_addr') ){ console.log(nebula.user.client.remote_addr); }
This function can not detect if an object is defined, so that must be done alongside
if ( typeof google != "undefined" && nebula.has(google, 'maps') ){ //Do something if google.maps is defined } else { //Do something else if google is undefined or doesn't have maps. }
This works for navigator support detection too.
if ( nebula.has(navigator, 'getBattery') ){ //Do something with the Battery API }
Or use it with Modernizr (as an alternative to yep/nope). Make sure Modernizr is enabled, though, or this would error out.
if ( typeof Modernizr != 'undefined' && nebula.has(Modernizr, 'batteryapi') ){ //Do something with the Battery API }
Additional Notes
Returns boolean.
Works well with nested objects- this helps prevent long conditionals like if ( nebula && nebula.client && nebula.client.remote_addr ){...}
Note: This function can not detect if an object is defined, so that must be done prior or alongside this function. See above example.
Deprecated notice: Use native JS Optional Chaining instead.