JavaScript Object-Oriented Programming Part 1

Very nice. I’ve been looking for someone to explain this to me forever…

Amazing! Just what I wanted to know!

There is the same kind of things in Java and strings are not considered primitives in Java so there is no reason to consider strings as primitives in Javascript also :). But it’s true that the discripancy of syntax allows for the confusion just take it as a commodity because strings are so commonly used the conceptors of Java and Javascript surely thought the advantage would outpass this syntaxic incoherence. Some people don’t think so, for example some python programmers take this as one pretext to criticize Java and prone proudly for the coherence of their loved python language ;).

Very good. Some widespread, lightweight techniques, such as javascript and html, are being employed a lot by non-professionals, in non-professional ways.Thus, it may be difficult to find good explanations (or, indeed, examples) of their use. This tutorial was an exception.

Good Article, but this is in every javascript book on the market.

specially i need of java script note justlike a meth obj and window obn and string obj seen me a notes i chapter to 8 chapter ok
thanks a lot

what about using prototype?

Look at Part 2 which discusses it.

-Ryan

Typo in the example above:
pimitive should be “primitive”

var pimitiveString1 = “This is a primitive string”;
var pimitiveString2 = String(“This is a primitive string”);

Great tutorial!! I used it for my first piece of OO based js function. It resizes an image to fit into its container, depending on whether the width or height is longer, yet keeping the aspect ratio.

Help yourself if needed:

function resizeImgOO(el)
{
function imgRatio(){
return (el.height / el.width);
}
function holderRatio(){
return (el.offsetParent.offsetHeight / el.offsetParent.offsetWidth);
}
function fitToContainer(){
if(imgRatio>holderRatio)
{
el.height = el.offsetParent.offsetHeight;
}
else
{
el.width = el.offsetParent.offsetWidth;
}
}

this.imgRatio = imgRatio;
this.holderRatio = holderRatio;
this.resize = fitToContainer;

}

var img = new resizeImgOO(document.getElementById(‘yourImgId’));

img.resize();

excellent explaination

very nice tutorial!

i’ve been trying to wrap my head around OO in JS for some time, and found this very easy to understand.

one suggestion: now that Part 2 does exist, maybe change the last sentence (starting with “Look out for Part 2”) to an active link:
http://www.sitepoint.com/article/oriented-programming-2

thanks!
Atg

Great Explanation, this gives different imagination about Java Script.

great article.It clearly explain the fundamentals of oops features in javascript

Well written article. Clear and easy to understand. I find the information very useful for me.

Inconsistent and factually incorrect article:

  1. Title reads, “JavaScript Object-Oriented…”
  2. Content reads, “First of all, JavaScript is not a full-blown OOP (Object-Oriented Programming) language, such as Java, but it is an object-based language”.

Secondly, JavaScript is 100% Object-Oriented language. It supports all three pillars of OO as suggested by Grady Booch.

Yes, of course, if the author has his own definition of OOPS, then it’s a different matter.

Have a look at:

eduzine.edujini-labs.com/archives/36-Exploring-OOPS-JavaScript-Style-Part-3-Polymorphism.html

(Please add http-colon-slash-slash yourself)

-Gaurav

Guarav, you are arguing on semantics but the truth is the author is correct. It is not a full-blown OOP language. Just because it uses a round-about way of satisfying the pillars of OOP, it can’t do it directly so it doesn’t “fully” qualify.

Nice article.

Ty for the nice tutorial

Nice tutorial, I’m used to C programming (procedural) style coding but now going into OOP programming and this helps alot…thanks!