# About Javascript

**URL:** <https://discuss.kotlinlang.org/t/about-javascript/1660>\
**Category:** JavaScript\
**Created:** [May 10, 2016, 2:09pm UTC](https://discuss.kotlinlang.org/t/about-javascript/1660 "2016-05-10T14:09:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lakedaemon](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/lakedaemon/32/1421_2.png) [@Lakedaemon](https://discuss.kotlinlang.org/u/Lakedaemon)\
**Post date:** [May 10, 2016, 2:09pm UTC](https://discuss.kotlinlang.org/t/about-javascript/1660/1 "2016-05-10T14:09:49Z")

</div>

I have known that Kotlin was awesome since I switched to it from java, 2 years ago.  
But recently, I have tried to use it for javascript target and I have been blown away by Kotlin…again. 😍

It is nice, simple and it works. I’m really impressed (I have been able to write a non trivial piece of javascript code really fast). 🕶

* * *

1. **Please document the javascript specific features !**  
the documentation for Kotlin:JS is lacking a lot : before you can setup a working project and understand how to make it work, you have to google search a lot of old blog posts and guess a lot. But after you get figured out the following stuff, it is pure awesomeness.

- Calling a top level Kotlin function from javascript

> // in Kotlin  
> yourPackage.yourFunction()
> 
> // in javascript  
> Kotlin.modules.yourLibrary.yourPackage.yourFunction();

- using the @Native annotation to use a javascript instance/object/function in Kotlin

> // accessing a javascript class
> 
> // in there, the javascript qualified type  
> @native(“math.expression.node.Node”)  
> // the corresponding javascript constructor (with the right parameters)  
> open class Node() {  
> // corresponding signature of the javascript methods you want to use  
> fun toTex():String  
> fun transform(action:(node:Node, path:String, parent:Node?)-\> Node):Node  
> fun clone():Node  
> }
> 
> // accessing a subclass of Node  
> @native(“math.expression.node.SymbolNode”)  
> class SymbolNode(val name: String):Node()
> 
> // using an object  
> @native(“math”)  
> object math {  
> fun parse(string:String):Node  
> }
> 
> // using a val (can’t add method signatures)  
> @native(“math”)  
> val math = noImpl
> 
> // creating a javascript class in Kotlin  
> val node = SymbolNode(“Hello”)
> 
> // accessing it’s value in Kotlin (the output goes in the javascript console)  
> println(node.name)
> 
> // accessing it’s value (the output goes in the html document)  
> document.writeln(node.name)
> 
> // using a method of a javascript object  
> val node2 = math.parse(“it really works !”)

- dynamic (working with javascript objects)

- js() (calling javascript from kotlin only with constant strings…)

- jsTypeOf()

1. Is there a way to use @Native class instances as keys in HashMap ?  
How does hashCode and equal work ? is it possible to overload them ?  
At the moment, I have to use instance.toString() as a key

2. is there a list of features available for the javascript target ? A roadmap ?

---

<div class="post-metadata">

**Author:** ![bashor](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/bashor/32/1431_2.png) [@bashor](https://discuss.kotlinlang.org/u/bashor)\
**Post date:** [May 12, 2016, 6:41pm UTC](https://discuss.kotlinlang.org/t/about-javascript/1660/2 "2016-05-12T18:41:44Z")

</div>

Hi, Lakedaemon!

Thanks for your feedback!

> [@Lakedaemon](#):
>
> Please document the javascript specific features !

We’ll work on it. Feel free to vote to [related issues](https://youtrack.jetbrains.com/issues?q=%23kotlin%20%23Docs%20%23unresolved%20and%20(JS%20or%20javascript)) to get updates.

> [@Lakedaemon](#):
>
> Is there a way to use @native class instances as keys in HashMap ? At the moment, I have to use instance.toString() as a key

Generic version right now use string representation, but it’s not good enough.

> [@Lakedaemon](#):
>
> How does hashCode and equal work ? is it possible to overload them ?

The general implementations lookups `equals_za3rmp$` for [equals](https://github.com/JetBrains/kotlin/blob/337078faf3bb716594471bf3966709fee3dc097d/js/js.translator/testData/kotlin_lib.js#L45-L63) and `hashCode` for [hashCode](https://github.com/JetBrains/kotlin/blob/337078faf3bb716594471bf3966709fee3dc097d/js/js.translator/testData/kotlin_lib.js#L65-L80).  
So if you want to override them in JS code you should add corresponding members to your object.

> [@Lakedaemon](#):
>
> is there a list of features available for the javascript target? A roadmap?

Most of language future will be available since 1.0.2 except reflection. Sorry, no public roadmap yet.
