Note that there are some explanatory texts on larger screens.

plurals
  1. POUncaught TypeError: object is not a function
    primarykey
    data
    text
    <p>I am using require on a site I am working on, and while working on the checkout, I ran across and issue. I am trying to change a credit card image to show the card number the activated to be whatever the number they put in is.</p> <p>However, everytime a key is pressed, I get this error:</p> <pre><code>Uncaught TypeError: object is not a function </code></pre> <p>And it says it's coming from line 12 of my "controller", which is:</p> <pre><code>var chkCard = new CreditImage($(this).val(), '.icon-credit-cards'); </code></pre> <p>Uncaught TypeError: object is not a function (repeated 3 times)</p> <p>Here is my "presenter" aka assets/scripts/presenters/CreditImage.js</p> <pre><code>require( [ 'jquery' ], function ($) { "use strict"; var CreditImage = function ($number, $el) { // Match and define var visa = $number.match(/^4[0-9]{12}(?:[0-9]{3})?$/); var mastercard = $number.match(/^5[1-5][0-9]{14}$/); var amex = $number.match(/^3[47][0-9]{13}$/); var discover = $number.match(/^6(?:011|5[0-9]{2})[0-9]{12}$/); var matched; // Create matched var if (visa) { matched = "visa"; } else if (mastercard) { matched = "mastercard"; } else if (amex) { matched = "amex"; } else if (discover) { matched = "discover"; } if (matched) { // Highlight the matched credit card $("."+$el+":not("+$el+"-" + matched + ")").addClass($el); $("."+$el).addClass($el+"-" + matched); } else { // No match, highlight them all $(".+$el).removeClass().addClass($el); } return matched; } } ); </code></pre> <p>And here is the "controller":</p> <pre><code>require( [ 'jquery', 'assets/scripts/presenters/CreditImage' ], function ($, CreditImage) { 'use strict'; $(function () { // Credit card validation $("#add-cc-card-number").bind("keyup", function () { var chkCard = new CreditImage($(this).val(), 'icon-credit-cards')); }); }); } ); </code></pre>
    singulars
    1. This table or related slice is empty.
    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