Javascript examples for Object:Object Method
access an object through its name as a string
<html> <head></head> <body> <script> var door = {"opened":false, "window":{"opened":false} }; function knocking(event){ var knockedThing = event.target.id; console.log(knockedThing); console.log("door is opened : " + window[knockedThing].opened); console.log("door window is opened : " + window[knockedThing].window.opened); }// w w w. ja v a 2 s . co m </script> <button id="door" onclick="knocking(event)">A door</button> </body> </html>