当前位置:网站首页>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
边栏推荐
- 一些问题一些问题一些问题一些问题
- 剑指 Offer 22. 链表中倒数第k个节点-快慢指针
- 92. Reverse linked list II byte skipping high frequency question
- ECMAScript history
- Use of todesk remote control software
- [binary number] maximum depth of binary tree + maximum depth of n-ary tree
- The system cannot be started after AHCI is enabled
- Solution of Navicat connecting Oracle library is not loaded
- Some questions some questions some questions some questions
- Low code development platform sorting
猜你喜欢

2021长城杯WP

QT modification UI does not take effect

stm32入门开发板选野火还是正点原子呢?

958. Complete binary tree test

RPC核心概念理解

394. 字符串解码-辅助栈

练习:求偶数和、阈值分割和求差( list 对象的两个基础小题)
![[logical fallacy in life] Scarecrow fallacy and inability to refute are not proof](/img/71/14a17128dbe0f02edb4db3da479ef2.jpg)
[logical fallacy in life] Scarecrow fallacy and inability to refute are not proof

Matlab / Simulink simulation of double closed loop DC speed regulation system

48. 旋转图像
随机推荐
31. Next arrangement
Commonly used functions -- spineros:: and spineros::)
Change Oracle to MySQL
tidb-server 的配置文件在哪里?
1217_使用SCons生成目标文件
239. Maximum value of sliding window (difficult) - one-way queue, large top heap - byte skipping high frequency problem
MySQL进阶学习之SQL优化【插入,主键,排序,分组,分页,计数】
Use of todesk remote control software
1217_ Generating target files using scons
双闭环直流调速系统matlab/simulink仿真
uni-app黑马优购项目学习记录(下)
ASP. Net core configuration options (Part 2)
31. 下一个排列
Self use learning notes - connectingstring configuration
[C] thoroughly understand the deep copy
Kubernetes service discovery monitoring endpoints
PC电脑使用无线网卡连接上手机热点,为什么不能上网
386. 字典序排数(中等)-迭代-全排列
Clickhouse SQL operation
01-初识sketch-sketch优势