Jump to content

Object oriented programming


Recommended Posts

Phew,I now try learn object oriented programming,using w3schools and one JS book,but I'm little confused about methods,objects,classes etc.I understand that first must create class,what contains then objects.And objects have methods,right?Well,can somebody make some very little object code,what I can use learning object programming?Then I have one more question about objects:What makes them so useful?What kind advantage they offer?Thanks you if somebody can help me.

Link to post
Share on other sites

OOP is usually used in languages where you interact with the user----and that interactivity is very important.

<script type="text/javascript">var coder=new Object() //declare the objectcoder.name="Choco" //set the method 'name' to 'Choco'coder.prefLang="JavaScript" //set the method 'prefLang' to 'JavaScript'document.write("Our new coder is "+coder.name+". He likes "+coder.prefLang+". Welcome!");</script>

That's a code to show you how to declare objects and use them. This is one that's an application in most sites.

<script type="text/javascript">x=document.getElementById("test") //set x to the object 'test'x.src="omghaxxors.gif" //set the method 'src' to 'omghaxxors.gif'</script>

Do you understand?

Link to post
Share on other sites

OOP lets coders make templates for objects: the classes. then, when they want to implement one, the call upon an instance of that object. so you can make var win1 = new Window(); and var win2 = new Window(); with only defining what a window should be and those two snipits of code. The new objects inherit the characteristics of the class. This allows for quick changes in a window.EG: a window has a width and height. in you code, you dont use OOP. You make 30 windows, each unique, by hand. Alot of code for making each object. The boss rolls by, and says whoops, windows now need an address as well. now you have to go back and individually change each one. in OOP, you just have each of the 30 an instance of the class window, and when you need to add address, you do it in the class definition. You might not see the advantage now, but try writing apps, not webpages. You will see the advantage.

Link to post
Share on other sites
OOP is usually used in languages where you interact with the user----and that interactivity is very important.CODE<script type="text/javascript">var coder=new Object() //declare the objectcoder.name="Choco" //set the method 'name' to 'Choco'coder.prefLang="JavaScript" //set the method 'prefLang' to 'JavaScript'document.write("Our new coder is "+coder.name+". He likes "+coder.prefLang+". Welcome!");</script>That's a code to show you how to declare objects and use them. This is one that's an application in most sites.CODE<script type="text/javascript">x=document.getElementById("test") //set x to the object 'test'x.src="omghaxxors.gif" //set the method 'src' to 'omghaxxors.gif'</script>Do you understand?
I understood first code clip,how it works,and what you can do with it(or so I think :) )but that second code was little strange for me.What it should do?I really don't know.I know what is getElementById,and such,but all last line is little strange for me :)
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...