且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

未捕获类型错误:未定义不是函数JavaScript模块

更新时间:2023-08-18 20:34:46

在运行使用MyClass的代码后,您正在定义MyClass。此外,将您的类填充到变量而不是将其称为传统方式会导致一些问题。试试这个:

You are defining MyClass after you run the code that uses MyClass. Also, stuffing your class into a variable rather than declaring it the "traditional" way causes some problems. Try this:

function MyClass ($element) {

  this.$element;
  console.log(this.$element);

  // more code...
}

$('.js-container').each(function (i, element) {
  new MyClass($(element));
  console.log($(element));
});

此外,移动 MyClass.prototype。实际MyClass中的定义。把它们放在后面。

Also, move your MyClass.prototype. definitions out of the actual MyClass. Put them after.