为什么JS小提琴给我的错误'未捕获TypeError: undefined不是一个函数'

Why does JS Fiddle give me the error `Uncaught TypeError: undefined is not a function `?

本文关键字:undefined 函数 一个 小提琴 JS 我的 错误 为什么 TypeError      更新时间:2023-09-26

我正在测试一个Plupload脚本时,我一直得到' Uncaught TypeError: undefined不是一个函数。

不知道为什么,我用jQuery的一个例子进行了测试。我得到相同的错误(se fiddle)。

谁能告诉我为什么这不起作用?

代码:

$( "div" ).greenify({
  color: "orange"
});
(function ( $ ) {
    $.fn.greenify = function( options ) {
       // Do stuff here
    };
}( jQuery ));

因为它们的顺序不对:

// First add the plugin
(function ( $ ) {
    $.fn.greenify = function( options ) {
       // Do stuff here
    };
}( jQuery ));
// THEN use it
$( "div" ).greenify({
  color: "orange"
});

更新小提琴

事物的一般顺序是:

    jQuery的script标签
  1. script标签的任何插件
  2. script标签用于您的代码