Can you please explain waht is the use of instanceof variable with example? | SoloLearn: Learn to code for FREE!

+1

Can you please explain waht is the use of instanceof variable with example?

3/18/2017 8:08:56 PM

Mohit Mehta

1 Answer

New Answer

+3

this is a simple document inspector for(k in document){ p.innerHTML += "."+k+"<br/>"; p.innerHTML += document[k]+"<br/>"; } if you are inspecting an object, the instanceof let you find out if the parts of the object are functions, other objects, or parameters. obj could be: window, or document, or any tag for(k in obj){ if(obj[k] instanceof Function){ p.innerHTML += "Function<br/>"; p.innerHTML += "Parameters: "+obj[k].length+"<br/>"; p.innerHTML += "."+k+"()<br/><br/>"; } } in this example it was important to my to find out how many parameters a function needs