www.webdeveloper.com
Results 1 to 6 of 6

Thread: I fail to create an object with a method

  1. #1
    Join Date
    Jan 2014
    Posts
    7

    I fail to create an object with a method

    I'd like to create an object in javascript, with methods that can be called. I read a webpage on how to do this, and then produced the following simple code:

    Code:
     var textplayer;
    
            textplayer = new Object();
    
            function textplayer() {
                this.getDuration = getDuration;
                function getDuration() {
                    var retval;
                    retval = 55;
                    return (retval);
                }
            }
        
            $(document).ready(function () {
                textplayer.max = textplayer.getDuration();
            })
    It does not work. In fact, 'getDuration' is not recognized.
    -- Thanks
    Gidmeister

  2. #2
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,355
    It looks like JQuery syntax. Did you include the library to allow the snippet to be executed?

  3. #3
    Join Date
    Jan 2014
    Posts
    7
    Quote Originally Posted by JMRKER View Post
    It looks like JQuery syntax. Did you include the library to allow the snippet to be executed?
    Yes I did. To be absolutely sure, I now removed all jquery syntax and just tried to call the method after the object was created.
    It just doesn't work.

  4. #4
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,213
    You declare textplayer as an object then create a function...

    you then have this.getDuration = getDuration; and getDuration, another function is then declared...

    Does not compute!
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  5. #5
    Join Date
    Jan 2014
    Posts
    7
    Thanks! I got the code off the internet, and the internet is sometimes unreliable. That's the answer.

  6. #6
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,213
    Sometimes people don't want to give freely and purposely put up examples that have errors or are wrong, why? Its the same as asking where did the universe come from.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles