Skip to content

false positive on click deprecated? #414

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
BackuPs opened this issue Feb 6, 2021 · 3 comments
Closed

false positive on click deprecated? #414

BackuPs opened this issue Feb 6, 2021 · 3 comments

Comments

@BackuPs
Copy link

BackuPs commented Feb 6, 2021

Hi

afbeelding

i have this js code

$.buttonMenu.defaults = {
	offset: [0, 0],
	layout: '<div/>',
	classes: {
		menu: 'theme-button-menu',
		subMenu: 'theme-button-sub-menu',
		hasSub: 'theme-has-sub',
		separator:'theme-button-menu-separator'
	},
	data: null,
	item: {
		text: '',
		"class": '',
		click: function () {}
	},
	beforeShow: function () {},
	afterShow: function () {},
	beforeHide: function () {},
	afterHide: function () {},
	onReady: function() {}
};

And i get a click deprecated notification on this part of the code on line 102

	 click: function (event) { item.click.call(this, item, event);	}

The full code of the function throwing the deprecation message is below.

	var builtItem = function (item) {
			item = $.extend({}, self.settings.item, item);
			if (typeof (item.sub) !== 'undefined') {
				var $sub = $('<ul/>');
				$.each(item.sub, function () {
					builtItem(this).appendTo($sub);
				});

				return $("<li/>", {
					"class": self.settings.classes.hasSub
				}).append($("<a/>", {
					"class": item["class"],
					text: item.text,
					click: function (event) {
						item.click.call(this, item, event);
					}
				})).append($sub);
			} else {
				if(typeof(item.type) !== 'undefined' && item.type == 'separator'){
					return $("<li/>").addClass(self.settings.classes.separator);
				}else{
					return $("<li/>").append($("<a/>", {
						"class": item["class"],
						text: item.text,
						click: function (event) {
							item.click.call(this, item, event);
						}
					}));
				}
			}
		};		 

even if i change the code to this i still get the deprecation message.

					return $("<li/>").append($("<a/>", {
						"class": item["class"],
						text: item.text,
						click: function (event) {
						}
					}));

afbeelding

The full code is attached to this in a zip file.

Why do i get the deprecated message on this? If i turn off jquery migrate the code works just fine. What am i missing here? Is this a false positive?

@mgol
Copy link
Member

mgol commented Feb 7, 2021

Yes, this is a deprecated method. See #410 (comment)

@mgol mgol closed this as completed Feb 7, 2021
@BackuPs
Copy link
Author

BackuPs commented Feb 7, 2021

Hi

This is not a answer to my question. I know the method is deprecated. But what is wrong with my code that it generates that message? What is the work around to avoid that message. There is no on('click', function(){}) or trigger(çlick') solution for this piece of code.

My question was. "is this a false positive?

Why is this issue closed so abrupt?

@BackuPs BackuPs mentioned this issue Feb 7, 2021
@dmethvin
Copy link
Member

dmethvin commented Feb 7, 2021

That code calls the click method. the "click" in the object you passed to $("<a />", object) calls the text, and click methods. I'm not a fan at all of that usage specifically because it hides that jQuery is calling methods. It can be rewritten as $("<a />").attr("class", ...).text(...).click(...) where it's very clear what's happening and why the deprecation notice appears.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants