首页 > 其他分享 >call/apply和 bind

call/apply和 bind

时间:2023-09-13 15:22:19浏览次数:36  
标签:name bind age person call apply 参数

call

接受多个参数,第一个参数表示 this 的指向,后面的多个参数都是传参

function person(name, age) {
	console.log(`my name is ${name} age is ${age}`);
}	
person.call(this, '大海', 18);

apply

接受两个参数,第一个参数表示 this 的指向,第二个参数为数组

function person(name, age) {
	console.log(`my name is ${name} age is ${age}`);
}
person.apply(this, ['大海', 18]);

bind

和 call 接受的参数一致,只是 bind会返回一个新的函数

function person(name, age) {
	console.log(`my name is ${name} age is ${age}`);
}	

let ocean = person.bind(this, '大海', 18);
ocean();

标签:name,bind,age,person,call,apply,参数
From: https://www.cnblogs.com/oceanus/p/17699780.html

相关文章

  • com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Java 8 date/time
    问题复现Java8date/timetypejava.time.LocalDateTimenotsupportedbydefault:addModule"com.fasterxml.jackson.datatype:jackson-datatype-jsr310"toenablehandling....在默认情况下Java8不支持LocalDateTime需要添加com.fasterxml.jackson.datatype:jackson-d......
  • linux NFS报错 无法重启rpcbind
    Failedtoregister(statd,1,tcp6/udp):svc_reg()err:RPC:Remotesystemerror-Noroutetohost 解决方案:net.ipv6.conf.all.disable_ipv6=0net.ipv4.conf.all.accept_redirects=0vi/etc/sysctl.conf==>net.ipv6.conf.all.disable_ipv6=0==>net.ipv4.c......
  • JavaScript中apply, call和bind的区别
    首先要知道,JavaScript中apply,call和bind的作用基本都是一样的,就是用来改变函数执行时的上下文,或者说改变函数的this对象指向在详细了解它们的区别之前,我们先来看一个例子varname="lucky";constobj={name:"martin",say:function()......
  • 【Kafka】ZooKeeper启动失败报错java.net.BindException_ Address already in use_ bi
    问题描述Kafka2.8.1ZooKeeper启动失败。zookeeper-server-start.bat../../config/zookeeper.properties[2023-09-0418:21:49,497]INFObindingtoport0.0.0.0/0.0.0.0:2181(org.apache.zookeeper.server.NIOServerCnxnFactory)[2023-09-0418:21:49,498]ERRORUnexpected......
  • bind函数的封装实现
    import{call}from'./call'/*自定义函数对象的bind方法bind(obj):返回一个新的函数,新函数内部会调用原来的函数,且this为bind()指定的第一参数的值*/exportfunctionbind(fn,obj,...args){console.log('bind()')//返回一个新函数return(...args2)......
  • LLamaSharp - .NET Binding for llama.cpp
    https://github.com/SciSharp/LLamaSharp TheC#/.NETbindingof llama.cpp.ItprovidesAPIstoinferencetheLLaMaModelsanddeployitonlocalenvironment.ItworksonbothWindows,LinuxandMACwithoutrequirmentforcompilingllama.cppyourself.Its......
  • mysql create procedure with in parameters ,call procedure
    //createprocedurestatementdelimiter$$usedb$$dropprocedureifexistsinsertIntoT1Table;createprocedureinsertIntoT1Table(innumint)begindeclareiintdefault1;while(i<num)doinsertintot1(name,abstract,author,content,summary)values(uui......
  • 报错解决 :Resolved [org.springframework.web.bind.MissingServletRequestParameterE
    报错解决:Resolved[org.springframework.web.bind.MissingServletRequestParameterException解决方法:RequestParam注解加上required=false属性。这样请求参数可以传null对象。如果没有加上required=false属性,这样请求参数传""空字符串也不会报错。如果没有加上required=......
  • WPF绑定(Binding)(4)
    数据绑定组件之间的绑定<StackPanel><Sliderx:Name="sd"Width="200"/><TextBoxText="{BindingElementName=sd,Path=Value}"/></StackPanel> 绑定数据源<Window.Resources>......
  • 解决error: no matching member for call to 'connect'
    在连接信号与槽时,报错解决error:nomatchingmemberforcallto'connect'原因由于信号被重载过,同名了,但是参数不一样,就会报错。这种情况下使用使用旧版语法connect(sender,SIGNAL(func()),receiver,SLOT(func1()))......