Hi,

You haven't given your `player` object a method called `loginfo` at
all, which is why you're getting that error (the property
`fred.loginfo` will come back `undefined`, which naturally fails when
you try to execute it via `()`). Also, you have a typo where you're
creating your `promote` function, it's a `promte` instead, so if you
got past the `loginfo` call you'd run into the same problem with
`promote`. And note that in your test code at the end, you create
`bob` and `alice` instances but you continue to call the methods on
the `fred` instance.

You said you're a new programmer. One thing to take away from this is
that computers are incredibly picky about small details. :-)

FYI, if a function is a constructor function (intended to be used with
`new`, like your `player` function), the convention is to use initial
caps on the name, e.g. `Player` with a capital `P`. Other functions
are written in camelCase. This helps differentiate functions that
aren't constructor functions from ones that are. It's only a
convention, but it's very widely-used.

If you're new to JavaScript, I did a series of blog posts/articles on
the language you may find helpful (or not, of course). If you start
here[1] and then work your way forward through the posts
chronologically, it may be helpful.

[1] http://blog.niftysnippets.org/2008/02/javascripts-curiously-powerful-or.html

HTH,
--
T.J. Crowder
Independent Software Engineer
tj / crowder software / com
www / crowder software / com

On Oct 16, 6:55 pm, Yossi <[email protected]> wrote:
> HI,
> I am new programmer.
> I looking to work with OOP in javascript.
> I heard about prototypejs, and I try to run my first CODE in
> firefox7.0.1
> And Prototype JavaScript framework, version 1.7 .
>
> The err that I got is "fred.loginfo is not function"
>
> below the code:
> ************************
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
> <html>
>   <head>
>   <script type="text/javascript" src="/prototype_js/prototype.js"></
> script>
>   <title></title>
>   </head>
>   <body>
> <script language="javascript" type="text/javascript">
> function player(n,s,r){
>     this.name=n;
>     this.score=s;
>     this.rank=r;
>
> }
>
> player.prototype.promte=function(){
>     this.rank++;
>     console.log("my new rank is: ",this.rank);
>
> }
>
> var fred=new player("fred,10000,5");
>     fred.loginfo();
>     fred.promote();
>
> var bob=new player("bob,50,1");
>     fred.loginfo();
>     fred.promote();
>
> var alise=new player("alise,233,33");
>     fred.loginfo();
>     fred.promote();
>
> </script>
>   </body>
> </html>

-- 
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.

Reply via email to