Forum Discussion

zakirhere's avatar
zakirhere
Occasional Contributor
12 years ago

Creating class, object and methods like OOP in javascript

Hi,



I notice there are keywords available such as public, private, class, etc which can be used to create Class and its Methods. By having those, it's very convenient to create our class which can be reused easily. 



I also found an example from the help file but when I tried, it gives syntax error.

http://support.smartbear.com/viewarticle/30854/



S
o, I was wondering if this (creating custom class) is something taken out as features of newer TestComplete 9.x? Apparently, the closest thing available for this one is ODT which is not easy to create complex methods.
  • googleid_105613's avatar
    googleid_105613
    Occasional Contributor
    What's happening in that article you posted a link to is they're exposing a VB.NET object to use within TestComplete, and then creating a .NET Interop object to allow that .NET component to communicate to TestComplete via COM.  From what I could understand from your post, not exactly what you wanted.  But here's what you can do...



    In JScript, you can create objects.  It's a little weird, but it works.



    You create your object like this...



    function foo ()

    {

      this.bar=function(x)

      {

        //Do some

      }



     this.Prop1="some value";

    }



    so further down you can say...



    var myFoo=foo;

    foo.Prop1="blahblahblah";



    It's not true OOP, like you'd expect.  You may get into trouble with inheritance.  Do some research on OOP in Javascript.  Remember that the JScript engine is based on Microsoft's JScript engine, which may not be entirely ECMA compliant.



    Yes, you can define an object in one unit, and include that unit in another through a //USEUNIT and use it in a second unit.  You can return "objects" from function calls and use them as well.
  • emmanuel_rivier's avatar
    emmanuel_rivier
    Occasional Contributor
    Hello,



    I am also interested to know more about Javascript OOP features in TestComplete.

    Is there something new related to that in TestComplete 10 ?



    Regards,



    Emmanuel