August 20, 2009

Javascript 19: Object Initializing


<script type="text/javascript"><br/>books={harrypotter:"harry",lordoftheflies:"ralph",chocolatewar:"jerry"}<br/></script>
<script type="text/javascript"><br/>document.write("I like the character "+books.harrypotter);<br/></script>


This will print a text on the window that says I like the character harry in harry. Now you can add this to it:


<script type="text/javascript"><br/>books={harrypotter:"harry",lordoftheflies:"ralph",chocolatewar:"jerry"}<br/></script>
<script type="text/javascript"><br/>document.write("I like the character "+books.harrypotter+ " and "+books.lordoftheflies);<br/></script>


You can add the other variables after that.


Powered by ScribeFire.



No comments:

Post a Comment