{....1}
最後の点は小数点
{....1}
{...obj}
{...(obj || {})}
{...null}
// {}
{...undefined}
// {}
{...false}
// {}
{...123}
// {}
{..."abc"}
// {0: "a", 1: "b", 2: "c"}
{...[10, 20]}
// {0: 10, 1: 20}
;[...null]
// Uncaught TypeError: null is not iterable
customElements.define("x-elem", class extends HTMLElement {
constructor(){
super()
this.attachShadow({mode: "open"})
this.render()
}
render(){
bind(this.shadowRoot)`
<div
onxxx=${eve => console.log("event xxx")}
onx-x=${eve => console.log("event x-x")}
onx_x=${eve => console.log("event x_x")}
>
<button onclick=${
eve => {
eve.target.dispatchEvent(new Event("xxx", {bubbles: true}))
eve.target.dispatchEvent(new Event("x-x", {bubbles: true}))
eve.target.dispatchEvent(new Event("x_x", {bubbles: true}))
}
}>event</button>
</div>
`
}
})
<div
onxxx=${eve => console.log("event xxx")}
onxXx=${eve => console.log("event xXx")}
></div>
document.body.innerHTML = `<div a="1" A="2" b="3"></div>`
document.body.innerHTML
// "<div a="1" b="3"></div>"
String name = 'Bob';
Future<String> lookUpVersion() async => '1.0.0';
void main() {
assert(sort is Compare<int>); // True!
}
if [x == y]:
print(1)
else:
print(0)
class Handle implements \IDisposable {
public function __dispose(): void {}
public function foo(): void {}
}
using ($x = new Handle()) {
$x->foo();
}
using new Handle();
function a(str) {
const reg = /\d*/g
return reg.test(str)
}
function a(){
return new Promise(resolve => {
setTimeout(() => {
console.log(1)
return 2
}, 1000)
})
}
function rec(){
a().then(e => rec())
}
rec()
console.log(true ? ...[1, 2] : 3)
true ? console.log(...[1, 2]) : console.log(3)
console.log(...(true ? [1, 2] : [3]))
for(const item of [1, 2, 3]){
console.log(item)
}
// 1
// 2
// 3
for(const item of {a: 1, b: 2}){
console.log(item)
}
// error
// オブジェクトが iterable じゃないと言われる
for(const item of Object.entries({a: 1, b: 2})){
console.log(item)
}
// ["a", 1]
// ["b", 2]
Object.prototype[Symbol.iterator] = function*(){ yield* Object.entries(this) }
for(const item of {a: 1, b: 2}){
console.log(item)
}
// ["a", 1]
// ["b", 2]
const a = WILLREPLACE`1n`
const b = WILLREPLACE`{...obj}`
js.replace(/WILLREPLACE`(.+?)`/g, "$1")