Jump to content

Object oriented programming


Fire Dragon

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 comment
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 comment
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 comment
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 comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...