012_call和apply区别

一、

function fn(a,b) {
	console.log(this);
}
fn.call(null,1,2);           //call为参数方式
fn.apply(null,[1,2]);     //apply为数组方式

/*输出=>
Object [global] {
  DTRACE_NET_SERVER_CONNECTION: [Function],
  DTRACE_NET_STREAM_END: [Function],
  DTRACE_HTTP_SERVER_REQUEST: [Function],
  DTRACE_HTTP_SERVER_RESPONSE: [Function],
  DTRACE_HTTP_CLIENT_REQUEST: [Function],
  DTRACE_HTTP_CLIENT_RESPONSE: [Function],
  global: [Circular],
  process:
   process {
     title: ‘/usr/local/bin/node‘,
     version: ‘v10.3.0‘,
     versions:
      { http_parser: ‘2.8.0‘,
        node: ‘10.3.0‘,
        v8: ‘6.6.346.32-node.9‘,
        uv: ‘1.20.3‘,
        zlib: ‘1.2.11‘,
        ares: ‘1.14.0‘,
        modules: ‘64‘,
        nghttp2: ‘1.29.0‘,
        napi: ‘3‘,
        openssl: ‘1.1.0h‘,
        icu: ‘61.1‘,
        unicode: ‘10.0‘,
        cldr: ‘33.0‘,
        tz: ‘2018c‘ },
     arch: ‘x64‘,
     platform: ‘darwin‘,
     release:
      { name: ‘node‘,
        sourceUrl:
         ‘https://nodejs.org/download/release/v10.3.0/node-v10.3.0.tar.gz‘,
        headersUrl:
         ‘https://nodejs.org/download/release/v10.3.0/node-v10.3.0-headers.tar.gz‘ },
     argv:
      [ ‘/usr/local/Cellar/node/10.3.0/bin/node‘,
        ‘/Users/00arunalldata00/009_mystudy/010_everest/001_Everest4/20180628/201804/7.fs/11.fn.js‘ ],
     execArgv: [],
     env:
      { PATH:
         ‘/usr/local/opt/openssl/bin:/opt/vagrant/bin:/usr/local/sbin:/usr/local/opt/sqlite/bin:/usr/local/opt/openresty-openssl/bin:/usr/local/opt/icu4c/sbin:/usr/local/mysql/bin:/usr/local/opt/icu4c/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/Applications/Wireshark.app/Contents/MacOS‘,
        NVM_RC_VERSION: ‘‘,
        FORCE_COLOR: ‘true‘,
        ELECTRON_NO_ATTACH_CONSOLE: ‘true‘,
        DEBUG_COLORS: ‘true‘,
        npm_config_color: ‘always‘,
        MOCHA_COLORS: ‘1‘,
        VERSIONER_PYTHON_VERSION: ‘2.7‘,
        LOGNAME: ‘arunyang‘,
        NVM_NODEJS_ORG_MIRROR: ‘https://nodejs.org/dist‘,
        XPC_SERVICE_NAME: ‘com.jetbrains.WebStorm.77156‘,
        PWD:
         ‘/Users/00arunalldata00/009_mystudy/010_everest/001_Everest4/20180628/201804/7.fs‘,
        NVM_CD_FLAGS: ‘-q‘,
        NVM_DIR: ‘/Users/arunyang/.nvm‘,
        SHELL: ‘/bin/zsh‘,
        PAGER: ‘less‘,
        LSCOLORS: ‘Gxfxcxdxbxegedabagacad‘,
        SECURITYSESSIONID: ‘186a8‘,
        OLDPWD: ‘/Applications/WebStorm.app/Contents/bin‘,
        VERSIONER_PYTHON_PREFER_32_BIT: ‘no‘,
        USER: ‘arunyang‘,
        ZSH: ‘/Users/arunyang/.oh-my-zsh‘,
        TMPDIR: ‘/var/folders/wy/v0w9vkf52836x21w_jz2wzlh0000gn/T/‘,
        SSH_AUTH_SOCK: ‘/private/tmp/com.apple.launchd.IKTjc3zbdP/Listeners‘,
        XPC_FLAGS: ‘0x0‘,
        NVM_IOJS_ORG_MIRROR: ‘https://iojs.org/dist‘,
        __CF_USER_TEXT_ENCODING: ‘0x1F5:0x0:0x0‘,
        Apple_PubSub_Socket_Render: ‘/private/tmp/com.apple.launchd.huBMuc0K3M/Render‘,
        LESS: ‘-R‘,
        LC_CTYPE: ‘‘,
        HOME: ‘/Users/arunyang‘ },
     pid: 3023,
     features:
      { debug: false,
        uv: true,
        ipv6: true,
        tls_alpn: true,
        tls_sni: true,
        tls_ocsp: true,
        tls: true },
     ppid: 2534,
     execPath: ‘/usr/local/Cellar/node/10.3.0/bin/node‘,
     debugPort: 9229,
     _startProfilerIdleNotifier: [Function: _startProfilerIdleNotifier],
     _stopProfilerIdleNotifier: [Function: _stopProfilerIdleNotifier],
     _getActiveRequests: [Function: _getActiveRequests],
     _getActiveHandles: [Function: _getActiveHandles],
     reallyExit: [Function: reallyExit],
     abort: [Function: abort],
     chdir: [Function: chdir],
     cwd: [Function: cwd],
     umask: [Function: umask],
     getuid: [Function: getuid],
     geteuid: [Function: geteuid],
     setuid: [Function: setuid],
     seteuid: [Function: seteuid],
     setgid: [Function: setgid],
     setegid: [Function: setegid],
     getgid: [Function: getgid],
     getegid: [Function: getegid],
     getgroups: [Function: getgroups],
     setgroups: [Function: setgroups],
     initgroups: [Function: initgroups],
     _kill: [Function: _kill],
     _debugProcess: [Function: _debugProcess],
     _debugEnd: [Function: _debugEnd],
     hrtime: [Function: hrtime],
     cpuUsage: [Function: cpuUsage],
     dlopen: [Function: dlopen],
     uptime: [Function: uptime],
     memoryUsage: [Function: memoryUsage],
     _rawDebug: [Function],
     moduleLoadList:
      [ ‘Binding contextify‘,
        ‘NativeModule events‘,
        ‘NativeModule internal/async_hooks‘,
        ‘NativeModule internal/errors‘,
        ‘Binding uv‘,
        ‘Binding buffer‘,
        ‘Binding async_wrap‘,
        ‘Binding config‘,
        ‘Binding icu‘,
        ‘NativeModule util‘,
        ‘NativeModule internal/encoding‘,
        ‘NativeModule internal/util‘,
        ‘Binding constants‘,
        ‘Binding util‘,
        ‘NativeModule internal/util/types‘,
        ‘Internal Binding types‘,
        ‘NativeModule buffer‘,
        ‘NativeModule internal/buffer‘,
        ‘NativeModule internal/process‘,
        ‘NativeModule assert‘,
        ‘NativeModule internal/assert‘,
        ‘NativeModule fs‘,
        ‘NativeModule path‘,
        ‘NativeModule internal/constants‘,
        ‘Binding fs‘,
        ‘NativeModule stream‘,
        ‘NativeModule internal/streams/pipeline‘,
        ‘NativeModule internal/streams/end-of-stream‘,
        ‘NativeModule internal/streams/legacy‘,
        ‘NativeModule _stream_readable‘,
        ‘NativeModule internal/streams/buffer_list‘,
        ‘NativeModule internal/streams/destroy‘,
        ‘NativeModule internal/streams/state‘,
        ‘NativeModule _stream_writable‘,
        ‘NativeModule _stream_duplex‘,
        ‘NativeModule _stream_transform‘,
        ‘NativeModule _stream_passthrough‘,
        ‘Binding fs_event_wrap‘,
        ‘NativeModule internal/fs/utils‘,
        ‘NativeModule internal/url‘,
        ‘NativeModule internal/querystring‘,
        ‘Binding url‘,
        ‘NativeModule internal/process/warning‘,
        ‘NativeModule internal/process/next_tick‘,
        ‘NativeModule internal/process/promises‘,
        ‘NativeModule internal/fixed_queue‘,
        ‘NativeModule internal/process/stdio‘,
        ‘Binding performance‘,
        ‘Binding trace_events‘,
        ‘NativeModule internal/inspector_async_hook‘,
        ‘Binding inspector‘,
        ‘NativeModule timers‘,
        ‘Binding timer_wrap‘,
        ‘NativeModule internal/linkedlist‘,
        ‘NativeModule internal/timers‘,
        ‘NativeModule internal/modules/cjs/loader‘,
        ‘NativeModule vm‘,
        ‘NativeModule internal/modules/cjs/helpers‘,
        ‘NativeModule console‘,
        ‘Binding tty_wrap‘,
        ‘NativeModule net‘,
        ‘NativeModule internal/net‘,
        ‘Binding cares_wrap‘,
        ‘Binding stream_wrap‘,
        ‘Binding tcp_wrap‘,
        ‘Binding pipe_wrap‘,
        ‘NativeModule internal/stream_base_commons‘ ],
     binding: [Function: binding],
     _linkedBinding: [Function: _linkedBinding],
     _events:
      { newListener: [Function],
        removeListener: [Function],
        warning: [Function] },
     _eventsCount: 3,
     _maxListeners: undefined,
     _fatalException: [Function],
     domain: null,
     _exiting: false,
     assert: [Function: deprecated],
     config: { target_defaults: [Object], variables: [Object] },
     setUncaughtExceptionCaptureCallback: [Function],
     hasUncaughtExceptionCaptureCallback: [Function],
     emitWarning: [Function],
     nextTick: [Function: nextTick],
     _tickCallback: [Function: _tickCallback],
     stdout: [Getter],
     stderr: [Getter],
     stdin: [Getter],
     openStdin: [Function],
     exit: [Function],
     kill: [Function],
     argv0: ‘/usr/local/bin/node‘,
     mainModule:
      Module {
        id: ‘.‘,
        exports: {},
        parent: null,
        filename:
         ‘/Users/00arunalldata00/009_mystudy/010_everest/001_Everest4/20180628/201804/7.fs/11.fn.js‘,
        loaded: false,
        children: [],
        paths: [Array] } },
  Buffer:
   { [Function: Buffer]
     poolSize: 8192,
     from: [Function: from],
     of: [Function: of],
     alloc: [Function: alloc],
     allocUnsafe: [Function: allocUnsafe],
     allocUnsafeSlow: [Function: allocUnsafeSlow],
     isBuffer: [Function: isBuffer],
     compare: [Function: compare],
     isEncoding: [Function: isEncoding],
     concat: [Function: concat],
     byteLength: [Function: byteLength],
     [Symbol(kIsEncodingSymbol)]: [Function: isEncoding] },
  clearImmediate: [Function: clearImmediate],
  clearInterval: [Function: clearInterval],
  clearTimeout: [Function: clearTimeout],
  setImmediate:
   { [Function: setImmediate] [Symbol(util.promisify.custom)]: [Function] },
  setInterval: [Function: setInterval],
  setTimeout:
   { [Function: setTimeout] [Symbol(util.promisify.custom)]: [Function] } }
Object [global] {
  DTRACE_NET_SERVER_CONNECTION: [Function],
  DTRACE_NET_STREAM_END: [Function],
  DTRACE_HTTP_SERVER_REQUEST: [Function],
  DTRACE_HTTP_SERVER_RESPONSE: [Function],
  DTRACE_HTTP_CLIENT_REQUEST: [Function],
  DTRACE_HTTP_CLIENT_RESPONSE: [Function],
  global: [Circular],
  process:
   process {
     title: ‘/usr/local/bin/node‘,
     version: ‘v10.3.0‘,
     versions:
      { http_parser: ‘2.8.0‘,
        node: ‘10.3.0‘,
        v8: ‘6.6.346.32-node.9‘,
        uv: ‘1.20.3‘,
        zlib: ‘1.2.11‘,
        ares: ‘1.14.0‘,
        modules: ‘64‘,
        nghttp2: ‘1.29.0‘,
        napi: ‘3‘,
        openssl: ‘1.1.0h‘,
        icu: ‘61.1‘,
        unicode: ‘10.0‘,
        cldr: ‘33.0‘,
        tz: ‘2018c‘ },
     arch: ‘x64‘,
     platform: ‘darwin‘,
     release:
      { name: ‘node‘,
        sourceUrl:
         ‘https://nodejs.org/download/release/v10.3.0/node-v10.3.0.tar.gz‘,
        headersUrl:
         ‘https://nodejs.org/download/release/v10.3.0/node-v10.3.0-headers.tar.gz‘ },
     argv:
      [ ‘/usr/local/Cellar/node/10.3.0/bin/node‘,
        ‘/Users/00arunalldata00/009_mystudy/010_everest/001_Everest4/20180628/201804/7.fs/11.fn.js‘ ],
     execArgv: [],
     env:
      { PATH:
         ‘/usr/local/opt/openssl/bin:/opt/vagrant/bin:/usr/local/sbin:/usr/local/opt/sqlite/bin:/usr/local/opt/openresty-openssl/bin:/usr/local/opt/icu4c/sbin:/usr/local/mysql/bin:/usr/local/opt/icu4c/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/Applications/Wireshark.app/Contents/MacOS‘,
        NVM_RC_VERSION: ‘‘,
        FORCE_COLOR: ‘true‘,
        ELECTRON_NO_ATTACH_CONSOLE: ‘true‘,
        DEBUG_COLORS: ‘true‘,
        npm_config_color: ‘always‘,
        MOCHA_COLORS: ‘1‘,
        VERSIONER_PYTHON_VERSION: ‘2.7‘,
        LOGNAME: ‘arunyang‘,
        NVM_NODEJS_ORG_MIRROR: ‘https://nodejs.org/dist‘,
        XPC_SERVICE_NAME: ‘com.jetbrains.WebStorm.77156‘,
        PWD:
         ‘/Users/00arunalldata00/009_mystudy/010_everest/001_Everest4/20180628/201804/7.fs‘,
        NVM_CD_FLAGS: ‘-q‘,
        NVM_DIR: ‘/Users/arunyang/.nvm‘,
        SHELL: ‘/bin/zsh‘,
        PAGER: ‘less‘,
        LSCOLORS: ‘Gxfxcxdxbxegedabagacad‘,
        SECURITYSESSIONID: ‘186a8‘,
        OLDPWD: ‘/Applications/WebStorm.app/Contents/bin‘,
        VERSIONER_PYTHON_PREFER_32_BIT: ‘no‘,
        USER: ‘arunyang‘,
        ZSH: ‘/Users/arunyang/.oh-my-zsh‘,
        TMPDIR: ‘/var/folders/wy/v0w9vkf52836x21w_jz2wzlh0000gn/T/‘,
        SSH_AUTH_SOCK: ‘/private/tmp/com.apple.launchd.IKTjc3zbdP/Listeners‘,
        XPC_FLAGS: ‘0x0‘,
        NVM_IOJS_ORG_MIRROR: ‘https://iojs.org/dist‘,
        __CF_USER_TEXT_ENCODING: ‘0x1F5:0x0:0x0‘,
        Apple_PubSub_Socket_Render: ‘/private/tmp/com.apple.launchd.huBMuc0K3M/Render‘,
        LESS: ‘-R‘,
        LC_CTYPE: ‘‘,
        HOME: ‘/Users/arunyang‘ },
     pid: 3023,
     features:
      { debug: false,
        uv: true,
        ipv6: true,
        tls_alpn: true,
        tls_sni: true,
        tls_ocsp: true,
        tls: true },
     ppid: 2534,
     execPath: ‘/usr/local/Cellar/node/10.3.0/bin/node‘,
     debugPort: 9229,
     _startProfilerIdleNotifier: [Function: _startProfilerIdleNotifier],
     _stopProfilerIdleNotifier: [Function: _stopProfilerIdleNotifier],
     _getActiveRequests: [Function: _getActiveRequests],
     _getActiveHandles: [Function: _getActiveHandles],
     reallyExit: [Function: reallyExit],
     abort: [Function: abort],
     chdir: [Function: chdir],
     cwd: [Function: cwd],
     umask: [Function: umask],
     getuid: [Function: getuid],
     geteuid: [Function: geteuid],
     setuid: [Function: setuid],
     seteuid: [Function: seteuid],
     setgid: [Function: setgid],
     setegid: [Function: setegid],
     getgid: [Function: getgid],
     getegid: [Function: getegid],
     getgroups: [Function: getgroups],
     setgroups: [Function: setgroups],
     initgroups: [Function: initgroups],
     _kill: [Function: _kill],
     _debugProcess: [Function: _debugProcess],
     _debugEnd: [Function: _debugEnd],
     hrtime: [Function: hrtime],
     cpuUsage: [Function: cpuUsage],
     dlopen: [Function: dlopen],
     uptime: [Function: uptime],
     memoryUsage: [Function: memoryUsage],
     _rawDebug: [Function],
     moduleLoadList:
      [ ‘Binding contextify‘,
        ‘NativeModule events‘,
        ‘NativeModule internal/async_hooks‘,
        ‘NativeModule internal/errors‘,
        ‘Binding uv‘,
        ‘Binding buffer‘,
        ‘Binding async_wrap‘,
        ‘Binding config‘,
        ‘Binding icu‘,
        ‘NativeModule util‘,
        ‘NativeModule internal/encoding‘,
        ‘NativeModule internal/util‘,
        ‘Binding constants‘,
        ‘Binding util‘,
        ‘NativeModule internal/util/types‘,
        ‘Internal Binding types‘,
        ‘NativeModule buffer‘,
        ‘NativeModule internal/buffer‘,
        ‘NativeModule internal/process‘,
        ‘NativeModule assert‘,
        ‘NativeModule internal/assert‘,
        ‘NativeModule fs‘,
        ‘NativeModule path‘,
        ‘NativeModule internal/constants‘,
        ‘Binding fs‘,
        ‘NativeModule stream‘,
        ‘NativeModule internal/streams/pipeline‘,
        ‘NativeModule internal/streams/end-of-stream‘,
        ‘NativeModule internal/streams/legacy‘,
        ‘NativeModule _stream_readable‘,
        ‘NativeModule internal/streams/buffer_list‘,
        ‘NativeModule internal/streams/destroy‘,
        ‘NativeModule internal/streams/state‘,
        ‘NativeModule _stream_writable‘,
        ‘NativeModule _stream_duplex‘,
        ‘NativeModule _stream_transform‘,
        ‘NativeModule _stream_passthrough‘,
        ‘Binding fs_event_wrap‘,
        ‘NativeModule internal/fs/utils‘,
        ‘NativeModule internal/url‘,
        ‘NativeModule internal/querystring‘,
        ‘Binding url‘,
        ‘NativeModule internal/process/warning‘,
        ‘NativeModule internal/process/next_tick‘,
        ‘NativeModule internal/process/promises‘,
        ‘NativeModule internal/fixed_queue‘,
        ‘NativeModule internal/process/stdio‘,
        ‘Binding performance‘,
        ‘Binding trace_events‘,
        ‘NativeModule internal/inspector_async_hook‘,
        ‘Binding inspector‘,
        ‘NativeModule timers‘,
        ‘Binding timer_wrap‘,
        ‘NativeModule internal/linkedlist‘,
        ‘NativeModule internal/timers‘,
        ‘NativeModule internal/modules/cjs/loader‘,
        ‘NativeModule vm‘,
        ‘NativeModule internal/modules/cjs/helpers‘,
        ‘NativeModule console‘,
        ‘Binding tty_wrap‘,
        ‘NativeModule net‘,
        ‘NativeModule internal/net‘,
        ‘Binding cares_wrap‘,
        ‘Binding stream_wrap‘,
        ‘Binding tcp_wrap‘,
        ‘Binding pipe_wrap‘,
        ‘NativeModule internal/stream_base_commons‘ ],
     binding: [Function: binding],
     _linkedBinding: [Function: _linkedBinding],
     _events:
      { newListener: [Function],
        removeListener: [Function],
        warning: [Function] },
     _eventsCount: 3,
     _maxListeners: undefined,
     _fatalException: [Function],
     domain: null,
     _exiting: false,
     assert: [Function: deprecated],
     config: { target_defaults: [Object], variables: [Object] },
     setUncaughtExceptionCaptureCallback: [Function],
     hasUncaughtExceptionCaptureCallback: [Function],
     emitWarning: [Function],
     nextTick: [Function: nextTick],
     _tickCallback: [Function: _tickCallback],
     stdout: [Getter],
     stderr: [Getter],
     stdin: [Getter],
     openStdin: [Function],
     exit: [Function],
     kill: [Function],
     argv0: ‘/usr/local/bin/node‘,
     mainModule:
      Module {
        id: ‘.‘,
        exports: {},
        parent: null,
        filename:
         ‘/Users/00arunalldata00/009_mystudy/010_everest/001_Everest4/20180628/201804/7.fs/11.fn.js‘,
        loaded: false,
        children: [],
        paths: [Array] } },
  Buffer:
   { [Function: Buffer]
     poolSize: 8192,
     from: [Function: from],
     of: [Function: of],
     alloc: [Function: alloc],
     allocUnsafe: [Function: allocUnsafe],
     allocUnsafeSlow: [Function: allocUnsafeSlow],
     isBuffer: [Function: isBuffer],
     compare: [Function: compare],
     isEncoding: [Function: isEncoding],
     concat: [Function: concat],
     byteLength: [Function: byteLength],
     [Symbol(kIsEncodingSymbol)]: [Function: isEncoding] },
  clearImmediate: [Function: clearImmediate],
  clearInterval: [Function: clearInterval],
  clearTimeout: [Function: clearTimeout],
  setImmediate:
   { [Function: setImmediate] [Symbol(util.promisify.custom)]: [Function] },
  setInterval: [Function: setInterval],
  setTimeout:
   { [Function: setTimeout] [Symbol(util.promisify.custom)]: [Function] } }
*/

  

原文地址:https://www.cnblogs.com/arun-python/p/9251092.html

时间: 2024-08-29 19:52:18

012_call和apply区别的相关文章

JS中call和apply区别有哪些 记录

一.call和apply区别 传递参数的方式.用法上不同,主要是参数不完全同 (1).B.Function.call(A,arg,arg) 这个例子是讲A对象“调用”B对象的Function(某个具体的方法). 注意call方法中的参数arg: a) arg的个数为零或多个; b) arg可以是任何类型,包括Array. call在这里译为“调用”,在JS中可以理解为“A对象调用B对象的某个方法”: (2).B.Function.apply(A,args) 这个例子是讲A对象“应用”B对象的Fu

call和apply区别

call和apply 基本上是一个意思 区别在于call的第二个参数可以是任意的类型,而apply的第二个参数必须是数组,也可以是arguments.call方法:语法:call(thisObj,Object)定义:调用一个对象的一个方法,以另一个对象替换当前对象.说明:call 方法可以用来代替另一个对象调用一个方法.call 方法可将一个函数的对象上下文从初始的上下文改变为由 thisObj 指定的新对象. 如果没有提供 thisObj 参数,那么 Global 对象被用作 thisObj.

CROSS APPLY和 OUTER APPLY 区别详解

SQL Server 2005 新增 cross apply 和 outer apply 联接语句,增加这两个东东有啥作用呢? 我们知道有个 SQL Server 2000 中有个 cross join 是用于交叉联接的.实际上增加 cross apply 和 outer apply 是用于交叉联接表值函数(返回表结果集的函数)的, 更重要的是这个函数的参数是另一个表中的字段.这个解释可能有些含混不请,请看下面的例子: -- 1. cross join 联接两个表 select * from T

CROSS APPLY 和 OUTER APPLY 区别

我们知道有个 SQL Server 2000 中有个 cross join 是用于交叉联接的.实际上增加 cross apply 和 outer apply 是用于交叉联接表值函数(返回表结果集的函数)的, 更重要的是这个函数的参数是另一个表中的字段. -- OUTER APPLYselect *  from TABLE_1 T1cross apply FN_TableValue(T1.column_a) -- OUTER APPLYselect *  from TABLE_1 T1outer 

call()与apply()区别

一.方法的定义 call方法: 语法:call(thisObj,Object)定义:调用一个对象的一个方法,以另一个对象替换当前对象.说明:call 方法可以用来代替另一个对象调用一个方法.call 方法可将一个函数的对象上下文从初始的上下文改变为由 thisObj 指定的新对象. 如果没有提供 thisObj 参数,那么 Global 对象被用作 thisObj. apply方法: 语法:apply(thisObj,[argArray])定义:应用某一对象的一个方法,用另一个对象替换当前对象.

JavaScript函数 bind call apply区别

1. apply calll 在JavaScript中 call 和 apply 都是为了改变某个函数运行时上下文而存在的, 换句话说就是为了改变函数内部的this的指向. 这里我们有一个新的对象 banana对象 但是没有say方法 我们可以通过call 或者apply用apple的say方法. 直接传入banana进去 使得this指向banana对象. apply和 call 本质上完全一样 只是 接收的参数不一样 call把参数(参数个数是确定的)逐个放进去.而apply的参数(参数是不

call与apply の 区别

/** * 用 add 来替换 sub,add.call(sub,3,1) == add(3,1) ,所以运行结果为:alert(4); */ function add(a,b){ alert(a+b); } function sub(a,b){ } add.call(sub, 3, 1);//alert 4 /** * call 的意思是把 animal 的ShowName方法放到cat上执行;所以运行结果为:alert('Cat'); */ function Animal(name){ th

apply,call,bind的区别

apply和call 在js中,apply,call,bind都是为了改变函数的执行上下文的而存在的,即改变函数内部this的指向. 下面的例子可以说明我们为什么要用apply和call,以及apply和call的区别. function Person(){}; Person.prototype = { name:'John', sayName:function(type){ console.log(this.name + " "+ type); } } var testPerson

apply,call,bind区别

js中有三个改变this指针的方法,分别是 apply,call,bind.很多人只知道能改变的this,但是具体的适用场景不是太清楚.我也是遇到坑后不断的实践发现了区别. call ,apply方法: 1 function Product(name, price) { 2 this.name = name; 3 this.price = price; 4 } 5 6 function Food(name, price) { 7 Product.call(this, name, price);