Note that there are some explanatory texts on larger screens.

plurals
  1. POJquery plugin error Object [object Object] has no method 'methodname'
    primarykey
    data
    text
    <p>I've created a jquery plugin for a project: <a href="http://jsfiddle.net/4kb9R/144/" rel="nofollow">http://jsfiddle.net/4kb9R/144/</a></p> <p>I want this plugin to be able to either be used as, of course a plugin, but also have a public method available called init that basically does the same thing.</p> <p>The problem I've encountered is that when I'm trying to run through the public init function I'm not able to run the private functions using:</p> <pre><code> self = this; //Start using the amountFormatter this.init = function(elements) { if(elements instanceof jQuery) { //Check the value of each element and update it accordingly elements.each(function() { var $this = $(this); var elementIsInput = $this.is("input"); value = $this.val() == "" ? $this.text().trim() : $this.val().trim(); value = (typeof value === 'undefined') ? '0' : value; value = thousandSeperator( convertNumber(roundingOfNumber(value, config.rounding)) ); //Checks whether we need to add the new amount as text or as a value return elementIsInput === true ? elem.val(addCurrencyToNumber(value)) : elem.text(addCurrencyToNumber(value)); }); } else { if(elements.length !== 0) { for (var i = 0; i &lt; elements.length; i++) { var value = elements[i]; //I get the error here, when I'm using self; elements[i] = self.addCurrencyToNumber( self.thousandSeperator(self.convertNumber(self.roundingOfNumber(value, config.rounding))) ); } return elements; } } }; this.init(elem); </code></pre> <p>I call the function like this:</p> <pre><code>var containerWithValue = $('.sf-insurance-amount'); var amountToTransform = containerWithValue.text(); var AmountsToFormat = ["4512.45", "784,687", "875943,5975"]; //Shows the original value... $(".sf-insurance-amount-original").text("Original: " + amountToTransform); // With options... containerWithValue.amountFormatter({ culture: "en", valuta: "euro", rounding: 3 }); var amountFormatterData = containerWithValue.data('amountFormatter'); var newAmounts = amountFormatterData.init(AmountsToFormat); console.log(newAmounts); $.each(newAmounts, function(index, value) { $(".sf-insurance-amount-provided ul li").eq(value-1).html(value); }); </code></pre> <p>Anyone have an idea as to why this is? Am I using the this keyword incorrectly here? I would love to get a solution for this.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload