Forum for Digital Media Arts (DMA) Students & Alumni
Home­Register­Gallery­FAQ­Search­Memberlist­Usergroups­Log in
Post new topic   Reply to topicShare | 
 

 Javascript Objects.

View previous topic View next topic Go down 
AuthorMessage
jorgelopez



Posts: 26
Join date: 2009-01-18
Age: 23

PostSubject: Javascript Objects.   Sat Aug 22, 2009 1:17 pm

All of the programming objects group collections of properties and functions into Objects. Javascript is no different. It has its native language objects and it gives us the ability to create our own custom objects. We can create one just as any other variable and adding values within curly brackets. An object in Javascript is created like this:

Code:
<script type="text/javascript">

var myObject = {};

</script>



To add Properties and Methods; they must go inside the curly brackets like this:

Code:
<script type="text/javascript">

var myObject = {

name: "jorge",
talk: function (){
   alert("hello");   
}

};

</script>


In the above I have declared an object called myObject with a property called name and a function called talk. In order to run the method it will be like this.

Code:
<script type="text/javascript">

myObject.talk();

</script>


It should show an alert box with the word hello.
Back to top Go down
View user profile
 

Javascript Objects.

View previous topic View next topic Back to top 
Page 1 of 1

Permissions of this forum:You cannot reply to topics in this forum
Digital Media Arts (DMA) :: Software :: Coding/Scripting-
Post new topic   Reply to topic