title: Is it possible to pass inline functions in Kotlin?
body: <p>When writing code for JavaScript with KotlinJs, we usually have to handle the <code>this</code> carefully.</p>
  
  <p>So we usually need this function:</p>
  
  <pre><code>inline fun &lt;T&gt; thisAs() = js("this")
  </code></pre>
  
  <p>and use it in somewhere:</p>
  
  <pre><code>this.click = {
      thisAs&lt;MyVueComponent.Data&gt;().username = "changed"
  }
  </code></pre>
  
  <p>Due to VueJs' inner logic, I have to generate JavaScript code <code>this.username</code>(<code>this</code> is hardcode), but which is ugly, I don't want to write <code>thisAs&lt;MyVueComponent.Data&gt;().username</code> every time I need a JavaScript <code>this</code>.</p>
  
  <p>So I tried to improve it by defining a function <code>defineMethods</code>, like following:</p>
  
  <pre><code>external interface VueComponent&lt;DATA, METHODS&gt; {}
  
  fun &lt;DATA, METHODS&gt; VueComponent&lt;DATA, METHODS&gt;.defineMethods(block: M.(() -&gt; DATA) -&gt; Unit): METHODS {
      val methods = jsObj&lt;M&gt;()
      block(methods, ::thisAs)
      return methods
  }
  </code></pre>
  
  <p>And I hope the inline function <code>thisAs</code> is still a inline function even if I pass it to the <code>block</code> as <code>::thisAs</code>, so I can rewrite the code like this:</p>
  
  <pre><code>this.methods = this.defineMethods { data -&gt;
      this.click = {
          data().username += "changed!"  // I want to write `data()` to generate a JavaScript `this`
      }
  }
  </code></pre>
  
  <p>But sadly, the function <code>data</code>(which is <code>::thisAs</code>) is not inline anymore, the code is not working properly.</p>
  
  <p>Is there any way to solve this?</p>
  
  <hr>
  
  <p>Update: </p>
  
  <ul>
  <li>Add a complete project to demo this problem, see: <a href="https://github.com/kotlin-demos/kotlin-vue-demo/tree/js-this-issue" rel="nofollow noreferrer">https://github.com/kotlin-demos/kotlin-vue-demo/tree/js-this-issue</a>. </li>
  </ul>