itnifl
asked on
JavaScript return property vs prototype property
What is the difference?
function() classname {
return {
parseValue: function (input) {
{ return _private(input); }
}
}
}
VSclassname.prototype.parseValue = function(input) {
return _private(input);
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I don't think the first example is even possible in Javascript. Javascript doesn't really have classes, but javascript objects are very similar to classes.
Are you confusing javascript with Java? These are two entirely separate programs. It's unfortunate that Netscape decided to use the name "javascript." Unfortunately, my Java knowledge is very rudimentary though I know my way around javascript very well.
Are you confusing javascript with Java? These are two entirely separate programs. It's unfortunate that Netscape decided to use the name "javascript." Unfortunately, my Java knowledge is very rudimentary though I know my way around javascript very well.
ASKER
Hello xmediaman, and thank you for your reply. I am aware of the difference between Java and JavasScript. This mixup that people often make is really a pain in the ass, I am guessing you are thinking the same.
Here I have written a small fiddle that exemplifies object oriented JavaScript:
http://jsfiddle.net/bMM5J/
Read the comments and try it out if you like.
I am looking for if there are any real differences in declaring attributes of an object in the first example shown in my question or the second(classname.prototype .parseValu e).
Here I have written a small fiddle that exemplifies object oriented JavaScript:
http://jsfiddle.net/bMM5J/
Read the comments and try it out if you like.
I am looking for if there are any real differences in declaring attributes of an object in the first example shown in my question or the second(classname.prototype
Sorry, I actually got hung up on line one of your first example where you have the parentheses after "function" and not after the "classname". Unfortunately, I'm not very adept in the difference between these two declarations. But I would think that the first would be problematic in that it must create and return an anonymous object every time it's executed.
ASKER
Yes, you may be right about that. I am not used to doing it this way as the first example shows and would like to understand it better. I have seen example code with this way of writing. The parentheses after the function keyword is a mistake from my side. It was supposed to be after the function name :p
ASKER
I am assuming you are right :)
ASKER