为什么 jquery-migrate-1.4.1.js 在成功 jQuery 升级后需要?

Why do I need jquery-migrate-1.4.1.js after a successful jQuery upgrade?

我已将 jQuery 从 1.3.1 升级到 1.12.4。一切正常,我准备删除 jquery-migrate-1.4.1.js 因为我只是在升级过程中将它用于调试目的。

当我从网站的 <head> 部分删除 jquery-migrate-1.4.1.js 时,该页面不再正常工作。 JavaScript/jQuery 中出现问题。我正在阅读 https://blog.jquery.com/2016/05/19/jquery-migrate-1-4-1-released-and-the-path-to-jquery-3-0/ 试图找到有关它的信息,这是我发现的:

Remove the Migrate 1.x plugin and ensure the page still works properly without it loaded.

为什么 jquery-migrate-1.4.1.js 在成功 jQuery 升级后需要 jquery-migrate-1.4.1.js?我认为它只是一个专门用于调试目的的 "behind the scenes" 脚本,不维护任何 jQuery/JavaScript 功能。

目前让您感到困惑的误解是 jquery-migrate-1.4.1.js 的目的是安装一些向后集中的解决方法,以使早期的 jQuery 代码在更新的 jQuery 同时还向您的 console.log 抱怨,以便您可以修复它。它实际上并没有改变你的代码。根据您的评论提供一些帮助您迁移的建议:

I see for example: "JQMIGRATE: jQuery.browser is deprecated". That is odd though, because the source of that error is jquery-migrate-1.4.1.js:45 and that is the jquery-migrate-1.4.1.js file, not that I am using jQuery.browser in my code.

执行日志记录的行在 jquery-migrate-1.4.1.js 中,因此错误似乎指向该文件,但是,调用 jQuery.browser 的行可能在您正在加载的插件中(这很常见在早期 jQuery 人们编写特定于浏览器的 hack 的日子里)您可以尝试在所有链接的 .js 文件(甚至是缩小的文件)中搜索 .browser 以至少隔离插件然后尝试寻找替代方案。

I see things such as: "jquery-migrate-1.4.1.js:45 JQMIGRATE: jQuery.fn.size() is deprecated; use the .length property". But I cannot find jQuery.fn.size() in my source code.

jQuery.fn.size() 的方法可能会像这样出现在您的代码中:

$('li.items').size()

jQuery.fn 只是 jQuery 元素函数的对象名称。因为您的 jQuery 对象基于您编写的 jQuery 选择器,所以可能很难搜索它,而是寻找类似 .size() 的东西,如果它显示在 jQuery 选择器,然后尝试将其替换为 .length(没有括号,因为 length 只是一个 属性)。

如果您有其他问题,最好将它们作为新问题发布,这样他们可以获得更直接和通常有用的答案。