Hacker News new | ask | show | jobs
by doktrin 4996 days ago
Being relatively new to cross-language compilation, how are one language's class APIs typically translated into another?

For example :

   [1,2,3].shuffle 
[turns into] =>

   (function() {
     var __opal = Opal, self = __opal.top, __scope = __opal, nil = __opal.nil, __breaker = __opal.breaker, __slice = __opal.slice;
  
     return [1, 2, 3].$shuffle()
   })();
Of course, since JS arrays do not have a "shuffle" method, the output reads :

   TypeError: Object 1,2,3 has no method '$shuffle'
Is the answer to simply use class/object methods that are present in both languages?
1 comments

Could probably also include something like Sugar.js or Underscore.js that tries to bring a lot of the missing syntactic sugar to JS.