当前位置:网站首页>JS interview question: FN call. call. call. Call (FN2) parsing
JS interview question: FN call. call. call. Call (FN2) parsing
2022-04-23 17:40:00 【Lost Camel】
There is such a JS Interview questions , ask fn.call.call.call.call(fn2) What is the result ?
First say call Internal principle of function :
- You can change the value of the function this;
- Execute function
Let's simulate Native call function :
Function.prototype.call = function(context, ...args){
context = context? Object(context) : window;
// change this
context.fn = this;
// Execute function
return context.fn(...args);
}
as follows :
function fn(){
console.log(11)
}
function fn2(){
console.log(22)
}
ask :
fn.call.call.call.call(fn2) What is the result ?
analysis :
- The front string
fn.call.call.call.callNo call , Just get the of the object call attribute , therefore , The result of this string is Function.call attribute . - So that string Namely
Function.call.call(fn2); It can also be cleaved into fn3.call(fn2). - according to call Principle ( Please refer to the above call simulation ), stay fn3 perform call, It is actually implemented in this way
fn2.fn3(). - because fn3 It's actually call function , therefore , fn2.fn3() Equivalent to
fn2.call(). - therefore , The final result of the above string of code , It's called fn2, So the result output 22.
版权声明
本文为[Lost Camel]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230552420727.html
边栏推荐
- Qt error: /usr/bin/ld: cannot find -lGL: No such file or directory
- Model problems of stock in and stock out and inventory system
- Future usage details
- Use of shell sed command
- 读《Software Engineering at Google》(15)
- Websocket (basic)
- 嵌入式系统中,FLASH中的程序代码必须搬到RAM中运行吗?
- MySQL进阶之索引【分类,性能分析,使用,设计原则】
- Seven cattle upload pictures (foreground JS + background C API get token)
- Use of todesk remote control software
猜你喜欢
![Using quartz under. Net core - [1] quick start](/img/80/b99417e88d544ca6e3da4c0c1625ce.png)
Using quartz under. Net core - [1] quick start

2.Electron之HelloWorld

【Appium】通过设计关键字驱动文件来编写脚本
MySQL installation

Qt error: /usr/bin/ld: cannot find -lGL: No such file or directory

土地覆盖/利用数据产品下载

QT modification UI does not take effect

PC电脑使用无线网卡连接上手机热点,为什么不能上网

Webapi + form form upload file

Exercise: even sum, threshold segmentation and difference (two basic questions of list object)
随机推荐
Compare the performance of query based on the number of paging data that meet the query conditions
MySQL installation
Future usage details
Self use learning notes - connectingstring configuration
JVM类加载机制
Ring back to origin problem - byte jumping high frequency problem
402. 移掉 K 位数字-贪心
239. 滑动窗口最大值(困难)-单向队列、大顶堆-字节跳动高频题
Using quartz under. Net core - [1] quick start
Change Oracle to MySQL
ASP. Net core configuration options (Part 2)
古代埃及希腊,数学用的什么进制
41. 缺失的第一个正数
MySQL进阶之索引【分类,性能分析,使用,设计原则】
一些问题一些问题一些问题一些问题
470. 用 Rand7() 实现 Rand10()
Clickhouse table engine
386. Dictionary order (medium) - iteration - full arrangement
[logical fallacy in life] Scarecrow fallacy and inability to refute are not proof
练习:求偶数和、阈值分割和求差( list 对象的两个基础小题)