Twitter hashtag: #esspec
便利ツール
時事ネタ
JSConf
8/31まで
フロントエンドカンファレンス関西
自己紹介 (近況報告)
syumai syumai.icon
Go / TSを書いて暮らしてます
ギプスが取れました
iwatsurut
とくに、イベントもなく過ごしています。
仕事で、Go で Web システムを作ることになった。
igrep(山本悠滋)
Claude CodeとNeovimを連携させるプラグインを軽く作ったが、ちょいちょいバグっている
前回のあらすじ
今回のメモ
code:js
(function () {
"use strict";
function f() {
console.log(this, typeof this);
}
f.apply(1); // 1 number
})();
(function () {
function f() {
console.log(this, typeof this);
}
})();
code:js
(function () {
"use strict";
function f() {
console.log(this, typeof this);
}
f.apply(); // undefined undefined
})();
(function () {
function f() {
console.log(this, typeof this);
}
f.apply(); // (globalThis) object
})();
code:js
(function () {
function Dog() {
this.name = "pochi";
}
Dog.apply(); // Dog(); を直接呼ぶのと大差ない
})();
console.log(name); // pochi
code:js
function f(a, b) {
console.log(a + b);
}
// function
console.log(typeof f);
// function (Call internal methodがあるので
console.log(typeof f.bind(1));
// f
console.log(f.name);
// bound f
console.log(f.bind(1).name);
// 2
console.log(f.length);
// 2
console.log(f.bind(1).length);
// 1
console.log(f.bind(1, 2).length);
// 0
console.log(f.bind(1, 2, 3).length);
// 0
console.log(f.bind(1, 2, 3, 4).length);
// 3
f.bind(undefined, 1)(2);
// 5
f.bind(undefined, 2)(3);
code:js
function f(a, b) {}
console.log(f.length); // 2
f.length = 3;
console.log(f.length); // 2
const desc = Object.getOwnPropertyDescriptor(f, "length");
Object.defineProperty(f, "length", {
...desc,
writable: true,
});
f.length = 3;
console.log(f.length); // 3
console.log(f.bind(undefined, 1, 2).length); // 1
f.length = Infinity;
console.log(f.bind(undefined, 1, 2).length); // Infinity
code:js
unction f() {}
const boundF = f.bind();
Object.getPrototypeOf(f).a = 1;
console.log(Object.getPrototypeOf(f)); // { a: 1 }
console.log(Object.getPrototypeOf(boundF)); // { a: 1 }
code:js
function F() {
console.log(this);
}
new F();
// F();
const boundF = F.bind(1);
code:js
function add(...nums) {
let result = this;
for (const n of nums) {
result += n;
}
return result;
}
console.log(add.apply(1, 2, 3)); // 6 console.log(add.call(1, 2, 3)); // 6