WebArtz - The Web Design Forum
Welcome to WebArtz, Guest!

WebArtz is a nice place for discussions related to web designing and coding. We help our members to code their own website templates with HTML and CSS. We give them advice on various issues.

To know more about WebArtz Forum, visit the About Us page.

At the moment, you are viewing the forum as a guest. As a guest you can't make post and participate in discussions. You need to register and become a member of the forum. Click the register link below and become a part of this forum.

Thank You


You are not connected. Please login or register

View previous topic View next topic Go down  Message [Page 1 of 1]

1Accespted Javascript - Creating Obejcts on Thu Apr 12, 2012 6:45 pm

Mr.Joker


Mr. WebArtz
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.

Code:
<script type="text/javascript">
function person(First_name,Last_name,Age) {
this.First_name = First_name;
this.Last_name = Last_name;
this.Age = Age;
}
var person_1 = new person("Peter","Jackson",19)
var person_2 = new person("John","Gruber",15)
document.write("My name is " + person_1.First_name + " " + person_1.Last_name + " and I am " + person_1.Age + " years old." + "<br />");
document.write("My name is " + person_2.First_name + " " + person_2.Last_name + " and I am " + person_2.Age + " years old.");
</script>

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. Very Happy

Notice : These tutorials are copyrighted by WebArtz Forum. You may not publish it on anywhere without written permission from the administrators.

2Accespted Re: Javascript - Creating Obejcts on Sat Jun 23, 2012 8:42 pm

RSguideMaker


Registered Member
Registered Member
Typo. In the title on the announcement, it says
Creating Obejcts

You may wish to change that.

This is a really good tutorial Mr.Joker. I will be using this in future when I become more familiar with JavaScript itself.

3Accespted Re: Javascript - Creating Obejcts on Wed Jul 11, 2012 10:20 pm

kelvinruki


Registered Member
Registered Member
thanks mr joker i want to knw how to use the html Cool

4Accespted Re: Javascript - Creating Obejcts on Thu Jul 12, 2012 1:40 am

Teknas


Registered Member
Registered Member
What exactly is an object?

http://gaminghub.forumotion.com

5Accespted Re: Javascript - Creating Obejcts on Thu Jul 12, 2012 2:20 am

Mr.Joker


Mr. WebArtz
Mr. WebArtz
An object can be anything you imagine. A car, a person, a school and all this objects have some properties as car(color, speed , acceleration etc.).

6Accespted Re: Javascript - Creating Obejcts on Thu Jul 12, 2012 2:21 am

Teknas


Registered Member
Registered Member
Any Pictures?

http://gaminghub.forumotion.com

7Accespted Re: Javascript - Creating Obejcts on Thu Jul 12, 2012 2:27 am

Mr.Joker


Mr. WebArtz
Mr. WebArtz

8Accespted Re: Javascript - Creating Obejcts on Thu Jul 12, 2012 4:02 am

Teknas


Registered Member
Registered Member
Nice!

http://gaminghub.forumotion.com

9Accespted Re: Javascript - Creating Obejcts on Fri Jul 13, 2012 11:02 am

aldoani


Registered Member
Registered Member
Thanks

http://dowan.7olm.org/

View previous topic View next topic Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum