认识Function.prototype.call】的更多相关文章

Function.prototype.toString这个原型方法可以帮助你获得函数的源代码, 比如: function hello ( msg ){ console.log("hello") } console.log( hello.toString() ); 输出: 'function hello( msg ){ \ console.log("hello") \ }' 这个方法真是碉堡了-, 通过合适的正则, 我们可以从中提取出丰富的信息. 函数名 函数形参列表…
Object.prototype 方法: hasOwnProperty 概念:用来判断一个对象中的某一个属性是否是自己提供的(主要是判断属性是原型继承还是自己提供的) 语法:对象.hasOwnProperty('属性名') var o = { name: 'jim' }; function Person() { this.age = 19; this.address='北京'; this.work='上海'; } Person.prototype = o; var p = new Person(…
方法: hasOwnProperty isPrototypeOf propertyIsEnumerable hasOwnProperty 该方法用来判断一个对象中的某一个属性是否是自己提供的( 住要用在判断属性是原型继承的还是自己提供的 ) 语法: 对象.hasOwnProperty( '属性名' ) -> boolean isPrototypeOf 凡是看到 of 翻译成 的, 反过来翻译: prototype of obj, 翻译成 obj 的 原型 因此该方法的含义是: xxx 是 xxx…
一.前言                                大家先预计一下以下四个函数调用的结果吧! var test = function(){ console.log('hello world') return 'fsjohnhuang' }test.call() // ① Function.prototype.call(test) // ② Function.prototype.call.call(test) // ③ Function.prototype.call.call(…
昨天边参考es5-shim边自己实现Function.prototype.bind,发现有不少以前忽视了的地方,这里就作为一个小总结吧. 一.Function.prototype.bind的作用 其实它就是用来静态绑定函数执行上下文的this属性,并且不随函数的调用方式而变化. 示例: test('Function.prototype.bind', function(){ function orig(){ return this.x; }; var bound = orig.bind({x: '…
本文大部分内容翻译自 MDN内容, 翻译内容经过自己的理解. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind Function.prototype.bind Syntax fun.bind(thisArg[, arg1[, arg2[, ...]]]) Parameters thisArg The value to be passed as the thi…
ECMAScript Edition5 IE9+支持原生,作用为将一个对象的方法绑定到另一个对象上执行. Function.prototype.bind = Function.prototype.bind || function(){ // 该方法当前所属的对象. var self = this; var args = Array.prototype.slice.call(arguments); // 绑定的对象. var o = args.shift(); // 如上操作后将绑定时的参数也绑定…
解析Function.prototype.bind 简介 对于一个给定的函数,创造一个绑定对象的新函数,这个函数和之前的函数功能一样,this值是它的第一个参数,其它参数,作为新的函数的给定参数. bind的作用 bind最直接的作用就是改变this的指向 // 定义函数 var checkNumericRange = function (value) { if (typeof value !== 'number') return false; else return value >= this…
简介 对于一个给定的函数,创造一个绑定对象的新函数,这个函数和之前的函数功能一样,this值是它的第一个参数,其它参数,作为新的函数的给定参数. bind的作用 bind最直接的作用就是改变this的指向 // 定义函数 var checkNumericRange = function (value) { if (typeof value !== 'number') return false; else return value >= this.minimum && value &l…
 昨天在网上看到一个很有意思的js面试题,就跟同事讨论了下,发现刚开始很绕最后豁然开朗,明白过来之后发现还是挺简单的,跟大家分享下!  题目如下: var a = Function.prototype.call.apply(function(a){return a;}, [0,4,3]); alert(a); 分析步骤如下: 1.将Function.prototype.call当成整体,call方法是由浏览器实现的本地方法,是函数类型的内部方法 var a = (Function.prototy…