calling methods within a prototype (oo) way

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • tuka

    calling methods within a prototype (oo) way

    Hi,

    I have 2 methods defined within a javascript objects
    that I would like to call in a third function within the same object.
    In the example below, func3 works well in FF but in IE7 it breaks.

    Any suggestions about how this may work ? I am sure this has to do
    with notation.
    I am calling the methods statically - so not instantiating a objects
    first.

    TIA,
    Tuka

    i.e.

    in a prototype object

    this.func1 = function(args) {
    //do stuff
    }

    this.func2 = function(args) {
    //do stuff
    }

    this.func3 = function(args) {
    this.func1();
    this.func2();
    }
  • RobG

    #2
    Re: calling methods within a prototype (oo) way

    On Apr 2, 8:13 am, tuka <tukaopal...@go oglemail.comwro te:
    Hi,
    >
    I have 2 methods defined within a javascript objects
    that I would like to call in a third function within the same object.
    In the example below, func3 works well in FF but in IE7 it breaks.
    >
    Any suggestions about how this may work ? I am sure this has to do
    with notation.
    I am calling the methods statically - so not instantiating a objects
    first.
    >
    TIA,
    Tuka
    >
    i.e.
    >
    in a prototype object
    >
    this.func1 = function(args) {
    //do stuff
    >
    }
    >
    this.func2 = function(args) {
    //do stuff
    >
    }
    >
    this.func3 = function(args) {
    this.func1();
    this.func2();
    >
    }
    It's always good to post working code (or at least code that, when
    executed, demonstrates the problem or issue) that can be easily copied
    and pasted.

    The following works fine in Firefox and IE at least:

    function Foo(){
    }

    Foo.prototype = {
    func1: function(){aler t('func1');},
    func2: function(){aler t('func2');},
    func3: function(){this .func1();}
    };


    var foo = new Foo();
    foo.func3(); // --func1


    --
    Rob

    Comment

    Working...