颿°ã new
ã§å¼ã³åºãããã¨ããã®ã³ã³ã¹ãã©ã¯ã¿ã¼ã® prototype
ããããã£ããçµæãªãã¸ã§ã¯ãã®ãããã¿ã¤ãã«ãªãã¾ãã
function Ctor() {}
const inst = new Ctor();
console.log(Object.getPrototypeOf(inst) === Ctor.prototype); // true
ãç¶æ¿ã¨ãããã¿ã¤ããã§ã¼ã³ãã«ãã³ã³ã¹ãã©ã¯ã¿ã¼é¢æ°ã® prototype
ããããã£ã¨ãçµæãªãã¸ã§ã¯ãã®ãããã¿ã¤ãéã®æä½ã«é¢ãã詳ããæ
å ±ãããã¾ãã
ãã颿°ã« prototype
ããããã£ãããã¨ããã ãã§ã¯ãã³ã³ã¹ãã©ã¯ã¿ã¼ã¨ãã¦èªããããã«ã¯ä¸ååã§ããã¸ã§ãã¬ã¼ã¿ã¼é¢æ°ã¯ prototype
ããããã£ãæã£ã¦ãã¾ãããã new
ã§å¼ã³åºããã¨ã¯ã§ãã¾ããã
async function* asyncGeneratorFunction() {}
function* generatorFunction() {}
代ããã«ãã¸ã§ãã¬ã¼ã¿ã¼é¢æ°ã® prototype
ããããã£ã¯ã new
ãªãã§å¼ã³åºãããã¨ãã«ä½¿ããã¾ããprototype
ããããã£ã¯ãè¿ããã Generator
ãªãã¸ã§ã¯ãã®ãããã¿ã¤ãã¨ãªãã¾ãã
ããã«ãä¸é¨ã®é¢æ°ã¯ prototype
ãæã£ã¦ãã¦ãã new
ã§å¼ã³åºãããå ´åã¯ç¡æ¡ä»¶ã«ä¾å¤ãéåºãã¾ããä¾ãã°ã Symbol()
颿°ã BigInt()
颿°ã¯ã new
ã§å¼ã³åºãããå ´åã«ã¯ä¾å¤ãçºçããã¾ãã Symbol.prototype
㨠BigInt.prototype
ã¯ãããªããã£ãå¤ã®ã¡ã½ãããæä¾ããã ãã®ããã«ããã®ã§ãã©ããã¼ãªãã¸ã§ã¯ããç´æ¥æ§ç¯ãããã¹ãã§ã¯ãªãããã§ãã
次ã®é¢æ°ã«ã¯ prototype
ããªãããã¨ãå¾ã§ prototype
ããããã£ãæåã§å²ãå½ã¦ãã¨ãã¦ããã³ã³ã¹ãã©ã¯ã¿ã¼ã¨ãã¦ã¯ä¸é©æ ¼ã§ãã
const method = { foo() {} }.foo;
const arrowFunction = () => {};
async function asyncFunction() {}
以ä¸ã®ãã®ã¯æå¹ãªã³ã³ã¹ãã©ã¯ã¿ã¼ã§ããã prototype
ãããã¾ãã
class Class {}
function fn() {}
ãã¤ã³ãããã颿°ã¯ prototype
ããããã£ãæã£ã¦ãã¾ããããæ§ç¯ãããã¨ãã§ããå ´åãããã¾ãã æ§ç¯ãããå ´åã代ããã«ã¿ã¼ã²ãã颿°ãæ§ç¯ãããã¿ã¼ã²ãã颿°ãæ§ç¯å¯è½ã§ããã°ãé常ã®ã¤ã³ã¹ã¿ã³ã¹ãè¿ãã¾ãã
const boundFunction = function () {}.bind(null);
颿°ã® prototype
ããããã£ã¯ãæ¢å®ã§ã¯ã1ã¤ã®ãããã㣠constructor
ãæã¤ãã¬ã¼ã³ãªãã¸ã§ã¯ãã§ãã constructor
ããããã£ã¯æ¸ãè¾¼ã¿å¯è½ã§ãåæä¸å¯ãæ§æå¯è½ãªããããã£ã§ãã
颿°ã® prototype
ã Object
以å¤ã®ä½ãã«å代å
¥ããã¦ããå ´åã颿°ã new
ã§å¼ã³åºãããã¨ãè¿ããããªãã¸ã§ã¯ãã®ãããã¿ã¤ã㯠Object.prototype
ã«ãªãã¾ããï¼è¨ãæããã°ãnew
㯠prototype
ããããã£ãç¡è¦ãããã¬ã¼ã³ãªãªãã¸ã§ã¯ããæ§ç¯ãã¾ããï¼
function Ctor() {}
Ctor.prototype = 3;
console.log(Object.getPrototypeOf(new Ctor()) === Object.prototype); // true
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4