1.0.3 • Published 5 years ago
scpfn v1.0.3
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>
- Run http-server (npm i -g http-server)
- Access http://localhost:8080