Forum Discussion

howie_'s avatar
howie_
Contributor
11 years ago

JScript operator overloading

Hey everyone, 



Does anyone know if it's possible to overload an operator in JScript? 



Here's what I'm doing: 

-------------------------------

Results.Pass += (test that returns 1 or 0);

Results.Total ++;





Here's what I'd like to be doing: 

--------------------------------------------

Results += (test that returns bool or 1||0 );



and then overload the "+=" operator in the Results class to do the addition/incrementing for me. 







I can't seem to find any information on this. I found something about C#Script supporting operator overloading, but it didn't say if JScript supported it or how to do it. Any help would be appreciated. 



Thanks, 

Howie 

1 Reply

  • Philip_Baird's avatar
    Philip_Baird
    Community Expert
    Hi Howie, it is not possible to do true operator overloading in JScript. This Stackoverflow article discusses some "workarounds" but I don't think they would work particularly well in the Test Complete runtime.




    Besides, you appear to be wanting to add an instance of Test to an instance of Results which really is wrong as both operands of an operator should be of the same type.


     


    In your case, I would implement a function on Result which takes a Test as a parameter, which is what I would consider to be correct in terms of OO principles.


     


    Regards,


    Phil Baird