JavaScript _za3lpa postfix


#1

Hi,

I try to create CommonJS from Kotlin and tried the factorial example from here: https://kotlinlang.org/docs/tutorials/create-library-js.html

That gives me a module that I can import using:

module.exports = function (Kotlin) {
  'use strict';
  var _ = Kotlin.defineRootPackage(null, /** @lends _ */ {
    org: Kotlin.definePackage(null, /** @lends _.org */ {
      sample: Kotlin.definePackage(null, /** @lends _.org.sample */ {
        factorial_za3lpa$: function (n) {
          return n === 0 ? Kotlin.Long.ONE : Kotlin.Long.fromInt(n).multiply(_.org.sample.factorial_za3lpa$(n - 1));
        }
      })
    })
  });
  Kotlin.defineModule('my.module', _);
  return _;
}(require('kotlin'));

Why is the function called factorial_za3lpa instead of plain factorial ?


#2

The postfix is based on an encoded version of the function signature. Since Kotlin 1.0.5, you can use the @JsName annotation to control the generated names in the JS code.