kotlin.js.JsName.<init>

<init>

JsName(name: String)

Platform and version requirements: JS

Gives a declaration (a function, a property or a class) specific name in JavaScript.

This may be useful in the following cases:

  • There are two functions for which the compiler gives same name in JavaScript, you can mark one with @JsName(...) to prevent the compiler from reporting error.
  • You are writing a JavaScript library in Kotlin. The compiler produces mangled names for functions with parameters, which is unnatural for usual JavaScript developer. You can put @JsName(...) on functions you want to be available from JavaScript.
  • For some reason you want to rename declaration, e.g. there's common term in JavaScript for a concept provided by the declaration, which in uncommon in Kotlin.

Example:

class Person(val name: String) {
    fun hello() {
        println("Hello $name!")
    }

    @JsName("helloWithGreeting")
    fun hello(greeting: String) {
        println("$greeting $name!")
    }
}

© 2010–2017 JetBrains s.r.o.
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.js/-js-name/-init-.html

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部