1 Javascript - Creating Obejcts Thu Apr 12, 2012 6:45 pm
Mr.Joker
Mr. WebArtz
Javascript - Creating Obejcts How to create objects in JavaScript |
Hello members of WebArtz, I am Mr.Joker and I will teach you how to create your own objects in javascript. As I said before , object have parameters and methods. Now , you will see how to make own object and use it. Its really simple.
Ta-da, a script for creating an object. Let me explain you how it work. I created a function with parameters inside it. A function is called person (because I want it be used for any person we create) and that function have parameters as First name, Last name, and Age. Those are common parameters for all new variables I will create. Then i say this.parameter = parameter . Its because I want that parameter become something new. I want to declare that that parameter can be used as method. In javascript we have methods as .legth , .toUpperCase() , toLowerCase() , and they are default and allready inside syntax but our method must be declared on this way. Now, when I close funciton , I create two new variables and both of them are equal to new person. Now you see our person can be used as new Array, new Date and etc. Inside brackets we name the person in order we set for it inside function. So for first variable person I will add first name, last name, and age and also for second person the same. Now inside document.write brackets I write person_1.First_name . As you can see person_1 is name of variable and it will be variable till I add dot and then add a parameter from function as name, age... Then that variable become a object and parameter become a method. I know its wierd now to udnerstand all this things, but there is no other way to understand it. |
Notice : These tutorials are copyrighted by WebArtz Forum. You may not publish it on anywhere without written permission from the administrators. |