Chrome javascript绑定函数不一致
如果浏览到about:blank,请打开脚本控制台并键入以下内容:Chrome javascript绑定函数不一致,javascript,google-chrome,ecmascript-5,google-chrome-devtools,Javascript,Google Chrome,Ecmascript 5,Google Chrome Devtools,如果浏览到about:blank,请打开脚本控制台并键入以下内容: var x = function() { console.info(this.toString() + ' -- ' + arguments.length.toString()); }; x.bind; 响应显示x.bind是在本机代码中实现的: function bind() { [native code] } 但是,当我在web应用程序的某个页面上调出脚本控制台并执行相同的语句时,似乎x.bind没有在本机上执行
var x = function() {
console.info(this.toString() + ' -- ' + arguments.length.toString());
};
x.bind;
响应显示x.bind是在本机代码中实现的:
function bind() { [native code] }
但是,当我在web应用程序的某个页面上调出脚本控制台并执行相同的语句时,似乎x.bind没有在本机上执行:
function (a){var b=this;return function(){b.apply(a,arguments)}}
是什么导致此实现像这样切换?我在javascript中设置的内容是否可能导致这种情况?我在页面上使用jQuery-这会有影响吗?不是jQuery,而是其他一些库/脚本添加了绑定到Function.prototype,其中一些库/脚本在不检查是否已经存在的情况下就这样做了,很高兴覆盖了本机实现。我假设您必须在页面上使用jQuery之外的其他脚本,以及其他脚本,无论是jQuery插件还是其他任何未经检查就被覆盖的脚本 我刚刚在Chrome中进行了测试,无论是否加载了jQuery,从实际页面中查看函数的bind属性都会显示本机代码标记。相反,如果我加载最新的原型,它会用自己的版本覆盖Chrome的原生版本 ,在Chrome上输出: Prototype not loaded jQuery not loaded
function bind() { [native code] }
Prototype not loaded
jQuery found: 1.6.2
function bind() { [native code] }
Prototype found: 1.7
jQuery not loaded
function bind(context) { if (arguments.length < 2 && Object.isUndefined(arguments[0])) return this; var __method = this, args = slice.call(arguments, 1); return function() { var a = merge(args, arguments); return __method.apply(context, a); } }
,在Chrome上输出:
Prototype not loaded
jQuery not loaded
function bind() { [native code] }
Prototype not loaded
jQuery found: 1.6.2
function bind() { [native code] }
Prototype found: 1.7
jQuery not loaded
function bind(context) { if (arguments.length < 2 && Object.isUndefined(arguments[0])) return this; var __method = this, args = slice.call(arguments, 1); return function() { var a = merge(args, arguments); return __method.apply(context, a); } }
,在Chrome上输出:
Prototype not loaded
jQuery not loaded
function bind() { [native code] }
Prototype not loaded
jQuery found: 1.6.2
function bind() { [native code] }
Prototype found: 1.7
jQuery not loaded
function bind(context) { if (arguments.length < 2 && Object.isUndefined(arguments[0])) return this; var __method = this, args = slice.call(arguments, 1); return function() { var a = merge(args, arguments); return __method.apply(context, a); } }
从您的示例中,您没有加载最新的原型,但是有东西正在覆盖Function.Prototype.bind。不是jQuery,而是其他一些库/脚本将bind添加到Function.Prototype,其中一些库/脚本在不检查是否已经存在的情况下进行了加载,很高兴地覆盖了本机实现。我假设您必须在页面上使用jQuery之外的其他脚本,以及其他脚本,无论是jQuery插件还是其他任何未经检查就被覆盖的脚本 我刚刚在Chrome中进行了测试,无论是否加载了jQuery,从实际页面中查看函数的bind属性都会显示本机代码标记。相反,如果我加载最新的原型,它会用自己的版本覆盖Chrome的原生版本 ,在Chrome上输出: Prototype not loaded jQuery not loaded
function bind() { [native code] }
Prototype not loaded
jQuery found: 1.6.2
function bind() { [native code] }
Prototype found: 1.7
jQuery not loaded
function bind(context) { if (arguments.length < 2 && Object.isUndefined(arguments[0])) return this; var __method = this, args = slice.call(arguments, 1); return function() { var a = merge(args, arguments); return __method.apply(context, a); } }
,在Chrome上输出:
Prototype not loaded
jQuery not loaded
function bind() { [native code] }
Prototype not loaded
jQuery found: 1.6.2
function bind() { [native code] }
Prototype found: 1.7
jQuery not loaded
function bind(context) { if (arguments.length < 2 && Object.isUndefined(arguments[0])) return this; var __method = this, args = slice.call(arguments, 1); return function() { var a = merge(args, arguments); return __method.apply(context, a); } }
,在Chrome上输出:
Prototype not loaded
jQuery not loaded
function bind() { [native code] }
Prototype not loaded
jQuery found: 1.6.2
function bind() { [native code] }
Prototype found: 1.7
jQuery not loaded
function bind(context) { if (arguments.length < 2 && Object.isUndefined(arguments[0])) return this; var __method = this, args = slice.call(arguments, 1); return function() { var a = merge(args, arguments); return __method.apply(context, a); } }
从您的示例来看,您没有加载最新的原型,但有东西正在覆盖Function.Prototype.bind。谢谢!你完全正确-我在我的页面上找到了一个脚本,它正在取代bind。@Flying:不用担心,很高兴这有帮助-非常感谢。你完全正确-我在我的页面上找到了一个脚本,它正在取代bind。@Flying:不用担心,很高兴这有帮助-