简体   繁体   中英

How to write $.fn.functionName = (function() { in jQuery 3

I have lots of functions like: $.fn.functionName = (function() {

I call them using: $(this).functionName();

This is deprecated in jQuery 3, how can I rewrite the function definition in order to make it work well (just like before).

Do you know a Library that is able to (automatically) replace the deprecated jQuery sintax? There's the jquery migration tool: https://blog.jquery.com/2016/05/19/jquery-migrate-1-4-1-released-and-the-path-to-jquery-3-0/ but it doesn't help me too much.

Thank you.

EDIT

Example log from jQuery 3 migration tool:

JQMIGRATE: jQuery.fn.focus() event shorthand is deprecated

console.trace()

migrateWarn
jQuery.fn[name]
$.fn.functionName/this.initData
$.fn.functionName
<anonymous>
_onReady
$.obj

您需要根据此https:// githubjQuery.fn.blur() to jQuery.fn.trigger('blur')替换jQuery.fn.blur() to jQuery.fn.trigger('blur')并将jQuery.fn.focus() to jQuery.fn.trigger('focus')替换jQuery.fn.focus() to jQuery.fn.trigger('focus') 。 com / mervick / emojionearea / issues / 217

I was using the "livequery" ( https://plugins.jquery.com/livequery/ ) and inside it I was calling the $.fn.functionName.

I know, it's an old code, but that was the problem. As freedomn-m said in a comment, the $.fn.xxx is not deprecated. I hope this will help others too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM