​ 目录 前言 导语 代码部分 前言 我是歌谣 歌谣的意志是永恒的 放弃很容易 但是坚持一定很酷 导语 手写bind ​编辑 代码部分 ``` Function.prototype.mybind = function (target) { //target:改变返回函数执行时的this指向 var
原创 2023-11-25 11:26:28
92阅读
 目录前言导语 代码部分前言我是歌谣 我有个兄弟 巅峰的时候排名c站总榜19 叫前端小歌谣 曾经我花了三年的时间创作了他 现在我要用五年的时间超越他 今天又是接近兄弟的一天人生难免坎坷 大不了从头再来 歌谣的意志是永恒的 放弃很容易 但是坚持一定很酷导语手写bind编辑 代码部分Function.prototype.mybind = function (target)
原创 2023-08-05 20:56:32
129阅读
​目录前言导语代码部分前言 我是歌谣 歌谣的意志是永恒的 放弃很容易 但是坚持一定很酷导语 手写bind​编辑代码部分``` Function.prototype.mybind = function (target) {//target:改变返回函数执行时的this指向 var obj = target || window;..
// _bind.js // 别人写法 Function.prototype._bind1 = function (context, ...args) { if (!context || context null) context = window; const fn = Symbol(); con ...
转载 2021-09-10 18:09:00
102阅读
2评论
Function.prototype.bind1 = function () { // const args = Array.from(arguments); const args = Array.prototype.slice.call(arguments); const target = arg ...
it
转载 2021-07-28 21:55:00
153阅读
2评论
# TypeScript中的bind手写实现及其深入解析 在JavaScript和TypeScript中,`bind`是一个非常重要的函数方法,它能够创建一个新函数,并将`this`上下文绑定到该函数上。这个功能在处理事件回调和传递上下文时尤其有用。本文将深入探讨`bind`的手写实现,帮助大家理解它的内部原理。 ## 一、函数和上下文 在讨论`bind`之前,我们首先要理解函数和上下文(`
原创 8月前
21阅读
必备知识点:js 【详解】函数中的 this 指向_js function this-CSDN博客。
原创 2024-03-21 15:22:32
780阅读
函数是有Function构建出来的,它本身是内有bind函数的,要手写bind函数可以写到Function.prototype上,这里用到了,原型链,this,call,apply,arguments,slice等知识。过程分为三步。 一、首先在Function.prototype写个bind1函数 ...
转载 2021-04-10 20:44:17
227阅读
2评论
call bind apply的作用都是可以进行修改this指向call 和 apply的区别在于参数传递的不同 bind 区别在于最后会返回一个函数。// call Function.prototype.MyCall = function (context) { if (typeof this !== "function") { throw new Error('t
原创 2022-04-07 09:34:50
127阅读
call、apply、bind的使用方法及区别作用:这三个函数的作用都是用来改变this的指向call使用方法fn.call(thisArg, arg1, arg2, arg3 ...)function fn1() {console.log(this) }const obj = { a: 1 } fn1.call(obj, 1, 2, 3, 4) // {a: 1}复制代码apply的用法fn.a
转载 2021-01-18 13:27:58
187阅读
2评论
1. 手写call原生call具备的三个功能改变this指向。调用call就是调用函数。(能够返回结果)实现代码function person(a,b,c) { return { name: this.name, a: a, b: b, c: c }}const egg = {name: 'hello'};Function.prototype.myCall = function(obj) { ob
原创 2022-02-25 14:02:11
173阅读
前言 大家好 我是歌谣 上节课我们已经说过了关于手写apply和手写call的讲解 这节课我们继续来进行手写bind的讲解bind演示<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta name="viewport" co...
原创 2023-07-29 00:39:43
59阅读
手写call、apply、bind函数 一、总结 一句话总结: 其实都不用记,用脑子去推就好了:核心点是为传进来的对象context添加fn这个函数属性,然后context就可以执行fn这个函数,也就是改变了fn的this指向 Function.prototype.myCall = function
转载 2020-03-20 07:33:00
146阅读
2评论
1. 手写call原生call具备的三个功能改变this指向。调用call就是调用函数。(能够返回结果)实现代码function person(a,b,c) { return { name: this.name, a: a, b: b, c: c }}const egg = {name: 'hello'};Function.prototype.myCall = function(obj) { ob
原创 2021-12-16 16:26:09
187阅读
callFunction.prototype.call = function call(context, ...params) {     context == null ? context = window : nullif (!/^(function|object)$/i.test(typeof context)) context = Object(context)let self = thi
转载 2021-01-31 19:56:06
134阅读
2评论
涉及面试题call,apply,bind函数内部实现是怎样的?考虑两点:第一个参数为undefined或null的时候,那么会转变为window改变了this执行,让新的对象可以执行该函数。callFunction.prototype.myCall = function(context) { if (typeof context === "undefined" || c...
原创 2021-11-19 13:53:09
341阅读
分析一下call的使用方法:call是显示绑定this指向,然后第一个参数是你所指向的this对象,后面跟着多个参数,以逗号隔开 function sum(num1,num2){ return num1 + num2 } sum.call({},1,2) // 3 上面是一个最简单的call使用方法 ...
转载 2021-09-24 17:22:00
170阅读
2评论
1. apply:改变函数的作用域,第一个参数是希望函数在哪个作用域被调用,或者说调用者是谁,第二个参数为数组形式传入函数参数. Function.prototype.apply = function (thisArg) { let context = thisArg || window; // w ...
转载 2021-09-30 15:05:00
140阅读
2评论
手写bind先看一下mdn对于bind的定义:bind()方法创建一个新的函数,在bindl
前言 大家好 我是歌谣 上节课我们已经说过了关于手写apply和手写call的讲解 这节课我们继续来进行手写bind的讲解 bind演示 <!DOCTY
原创 2023-08-07 00:30:04
73阅读
  • 1
  • 2
  • 3
  • 4
  • 5