开发者社区> 问答> 正文

[requirejs]为什么会提示其中一个依赖 undefined??报错

正在学requirejs,写了个小Demo,不知为何提示其中一个依赖undefined:

这个依赖是widget.js,代码如下:


// 自定义Widget抽象类
define(['jquery'],function($){
	function Widget(){
		// 最外层容器
		this.boundingBox = null;
	}

	Widget.prototype = {
		// type 为自定义类型,handler 为处理函数
		// 开启监听的方法
		on:function  (type,handler) {
			if(typeof this.handlers[type] ==  'undefined'){
				this.handlers[type] = [];
			}
			this.handlers[type].push(handler);
			// 连缀语法
			return this;
		},
		// 触发事件的方法,data为执行具体某个参数时可能会用到的参数,可以为空
		fire:function  (type,data) {
			if(this.handlers[type] instanceof Array){
				var handlers = this.handlers[type];
				for (var i = 0; i < handlers.length; i++) {
					handlers[i](data);
				};
			}
		}
		render:function(container) {
			this.renderUI();
			this.handlers={};
			this.bindUI{};
			this.syncUI{};
			$(container||document.body).append(this.boundingBox);
		},
		destroy:function  () {
			this.destructor();
			this.boundingBox.off();
			this.boundingBox.remove();
		},
		renderUI:function  () {},
		bindUI:function  () {},
		syncUI:function  () {},
		destructor:function  () {},

	}

	return {
		Widget:Widget
	}
});



程序入口是main.js,在这里就报错了,如下:



require.config({
	paths:{
		// 路径值去掉js后缀文件名
		jquery:'jquery-2.1.0.min',
		jqueryUI:'http://libs.baidu.com/jqueryui/1.10.2/jquery-ui.min'
	}
});
// 程序入口
require(['widget','jquery'],function (w,$) {
	$(function() {
		alert(new w.Widget());
	});
});



main.js和widget.js在同一文件夹里,不知道是什么原因,哪位同仁能提示一二,不胜感激!


展开
收起
爱吃鱼的程序员 2020-06-14 21:07:29 689 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    widget.js也要配置到paths里多看看文档哦

    fire函数后少个逗号。

    2020-06-14 21:07:48
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载