Creating a local reference to a jQuery.data key

前端 未结 2 676
别那么骄傲
别那么骄傲 2021-01-21 09:32

I\'m doing some testing on jQuery.data(), and I\'m trying to create a local reference to a certain data-key, which I hopefully can change locally and still affect \

2条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-21 10:13

    I am not going to lie - that code is incredibly confusing. Is there a reason why you need to use all those self-executing functions? It seems (at least to this layperson) that you could code this in a much more straightforward way to achieve your goal.

    Anyway I am not sure this is the answer you're looking for, but I just stopped the debugger inside AddError so I could understand its scope and what was available. So all you need to do to make it return the output you want is this:

    http://jsfiddle.net/qN7wF/2/

    functions = {
        AddError: function() {
            console.log(total);
            $(container).data('errors').total++;
            errors.length++;
      },
    

    But given the context... I'm guessing there must be more at play.

提交回复
热议问题