takayoshiotake / scpfn.js

Scope functions like Kotlin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

scpfn.js

Scope functions like Kotlin

Start

$ npm install scpfn

index.js:

const scpfn = require('scpfn').default;

scpfn.inject(Object.prototype);
console.log("test".let(it => it.toUpperCase())); // TEST
$ node index.js
TEST

Browser

  • Download dist/scpfn.min.js
  • index.html:
<script type="module">
import scpfn from './scpfn.min.js'
scpfn.inject(Object.prototype)

document.body.appendChild(document.createElement('span').also(it => {
    it.innerText = "Hello"
    let s = it.style
    s['color'] = 'white'
    s['background-color'] = 'darkgray'
}))
document.body.appendChild(document.createElement('span').also(it => {
    it.innerText = ", world!"
    let s = it.style
    s['color'] = 'black'
    s['background-color'] = 'lightgray'
}))
</script>

result base64

About

Scope functions like Kotlin


Languages

Language:JavaScript 100.0%