Please note that Sahi's development and support teams do not actively monitor this. This is more a community forum. If you are a Sahi Pro user looking for commercial support, please email support @ with your query.

Is there any easier way to handle function invoking?

ilovepumpkinilovepumpkin Members
edited 11:45AM in Sahi - Open Source
I am using the object orientate programming mode. My .sah file content is below. I assumed "_assertEqual("hello",this.method1())" should work but it does not. Now I have to define a variable first to get the method2() return value first to make it work but it looks redundant, doesn't it? Is there any easier to handle the function invoking from another function? Thanks.

1 function ClassA(){
2 this.method1=function(){
3 return "hello"
4 }
6 this.method2=function(){
7 // this does not work now but it should work in normal JS code
8 //_assertEqual("hello",this.method1())
10 var $value=this.method1()
11 _assertEqual("hello",$value)
12 }
13 }
15 new ClassA().method2()


  • hi ilovepumkin

    OO javascript is pretty nice, I used

    But including Sahi APIs is tricky because some function calls in APIs need browser tags to work and I don't know if this is possible within a function.. see

  • I have already written some OO style code and basically I think they work with Sahi. However, some code don't work as is like what I mentioned in this post so I am asking Sahi team if there is any better solution other than assigning the function return value to a variable first.

    For your post. Actually it may not need "browser" tag. Instead, you can assign the function return value to a variable first if you don't like to put the function declaration into the browser tag. See below. Certainly if you function involves DOM operations, you have to put it into browser tag.
    function someFunction($string){
    return $string;

    var $result=someFunction("something")
    _assertNotExists("something", "Here i want" + $result);
  • Sure, but this creates the redundancy you where talking about. Where the only solution i know about yet are these browser tags. Did you try the browser tags within a function? Or defining like
    function myAssert () {
     function ClassA(){
             return "hello"
    new ClassA().method2()
  • I would like to keep my current implementation although it has to involve additional variable assignment than using the browser tag. The reason is that using browser tag breaks the OO style and the sample code I posted is just to make the issue look simple but in fact the methods may use the class-level variables so your sample code does not work for that situation. Anyway thanks for replying me!
  • Hi there,
    Is anybody using OO javascript these days with Sahi ?
    If yes what are the main drawbacks
Sign In or Register to comment.