0

I have something like this:

function removeProduct(dataProduct) {
  console.log(dataProduct)
}
<button data-shop-listing="{'foo': 'fooData'}" type="button" onclick="removeProduct(this.getAttribute('data-shop-listing'));">Remove</button>

Everything looks fine, right? The problem is I have no-unused-vars linter activated and it is a requirement not to turn it off.

what would be an elegant approach to achieve this?

Thanks.

George
  • 6,630
  • 2
  • 29
  • 36
superTramp
  • 165
  • 2
  • 3
  • 11
  • 1
    `` using `function removeProduct(but){ var product = JSON.parse(but.getAttribute("data-shop-listing")); ... }` If you have jQuery you do not need the JSON.parse, just $(this).data("shop-listing").foo - however this question is better asked at codereview – mplungjan Feb 22 '17 at 12:09
  • Sorry if I'm being dense but is the problem with the linter having issues with the function? If so could you change it to `var removeProduct = function(dataProduct) {console.log(dataProduct)}` – George Feb 22 '17 at 12:11
  • Then it won't work because functions are working with an instance of another class. – superTramp Feb 22 '17 at 12:13
  • 1
    Create the function like this: `window.removeProduct = function(dataProduct)...` – XCS Feb 22 '17 at 13:49
  • @Cristy I read is not very efficient to have global functions. In this case is the only solution to the problem? – superTramp Feb 22 '17 at 16:52
  • @superTramp Your function is global anyway... it does exactly the same thing, only that the linter won't show an error. – XCS Feb 22 '17 at 19:13

0 Answers0