0

How to convert the following Java code to JScript:

return ((IPOSBasket) basket).getOriginalCashierID();

When executing the above code in Java, it works fine. But if I try to execute as a JScript, I am getting NULL value.

Gokul Nath KP
  • 15,485
  • 24
  • 88
  • 126
  • 2
    http://stackoverflow.com/a/245068/2454376 – mishik Jul 10 '13 at 08:03
  • 1
    Are you talking about [JScript](http://en.wikipedia.org/wiki/JScript) or [Javascript](http://en.wikipedia.org/wiki/JavaScript)? – mthmulders Jul 10 '13 at 08:07
  • I'm not sure anyone really talks about JScript.. – Stephen Jul 10 '13 at 08:12
  • 1
    If it is jScript, are you using it to compile .net assemblies? http://en.wikipedia.org/wiki/JScript_.NET That jScript is typed. Ecma javascript and jscript in IE are not typed so there is no need for conversion (unless you need string to number). – HMR Jul 10 '13 at 08:13
  • 1
    In case you try to run this script in a browser then `return basket.getOriginalCashierID();` will do. – HMR Jul 10 '13 at 08:17

3 Answers3

3

At the risk of getting downvotes XD

Java and Javascript are similar like Car and Carpet are similar.

Greg Hewgill 2008

Community
  • 1
  • 1
Jamie Hutber
  • 26,790
  • 46
  • 179
  • 291
0

You shouldn't need to cast anything, how are you getting the basket variable?

Also, as a good practice don't do any operations in a return statement, it sometimes hides errors/problems in code and harms readability.

So if it is JScript:

var basket : IPOSBasket = IPOSBasket(x); // this is made up, don't know what you are doing here.
var originalCashierID = basket.getOriginalCashierID();
return originalCashierID;
Daniel Goncalves
  • 308
  • 1
  • 10
0

As mentioned by HMR in comment, the following line works fine:

return basket.getOriginalCashierID();
Gokul Nath KP
  • 15,485
  • 24
  • 88
  • 126