www.webdeveloper.com
Results 1 to 4 of 4

Thread: Function within function within function

  1. #1
    Join Date
    Jun 2012
    Posts
    3

    Exclamation Function within function within function

    Hmm, maybe this is possible or not but I have tried and failed, what I would like is to be able to do the following:

    Code:
    function Player()
    {
    	this.name = "Bob";
            this.animate= function(direction)
    	{
    		return direction;
                    stop = function() {
                           //code here
                    }
    	} 
    }
    Then I simply want to do the following:

    Code:
    var player = new Player();
    player.animate("left").stop();
    I tried many different ways and the only way I could get it to work is by using:

    Code:
    player.animate.stop();
    I know many will know how to do this but I tried researching and couldn't find any results, thanks if you help...
    Joel.

  2. #2
    Join Date
    Jun 2012
    Location
    Dark Side of the Moon
    Posts
    70
    everything after return would not be executed, it need to be blocked off with a switch, loop, or if statements. The code you gave in the first block does not do anything by return in the first statement.

  3. #3
    Join Date
    Jun 2012
    Posts
    3
    Quote Originally Posted by burnme View Post
    everything after return would not be executed, it need to be blocked off with a switch, loop, or if statements. The code you gave in the first block does not do anything by return in the first statement.
    Oh right, though I don't need the return statement, if I remove it... it still doesn't work.

  4. #4
    Join Date
    Jan 2011
    Location
    United Kingdom, London
    Posts
    117
    Code:
    function Player()
    {
    	this.name = "Bob";
            this.animate= function(direction)
    	{
                    this.stop = function() {
                          return 'kawabanga';
                    }
    return this;
    	} 
    }
    then

    Code:
    var player = new Player();
    player.animate("left").stop();
    Javascript, jQuery / Prototype & PHP expert ready to complete your work on Freelancer.co.uk - Hire Me at https://www.freelancer.co.uk/users/1...&action=hireme

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