I'm interesting in how JS source code works and seems that I should to use ECMAScript® Language Specification. In my case I tried to write my own implemetetion of Function.prototype.call
Function.prototype._call = function (thisArg = {}, ...arg) {
// 1. Let func be the this value.
let func = this
// 2. If IsCallable(func) is false, throw a TypeError exception.
if (typeof func !== 'function') {
throw new TypeError(this + "isn't callable")
}
// 3. Perform PrepareForTailCall().
thisArg.func = func
// 4. Return ? Call(func, thisArg, args).
return thisArg.func(...arg)
}
It works, but I'm not sure that my implementation is correct and would like to compare it with the "official" implementation. Where may I find code references for ECMAScript examples? Thank you!