javascript-将Backbone.js与_.noConflict()一起使用
作者:互联网
我希望将Backbone.js与命名空间下划线库一起使用.有谁知道我怎么能告诉Backbone指的是下划线而不是_
谢谢!
马特
解决方法:
截止到今天(0.5.3版),骨干网本身还没有为此做好准备,但是可以做到:
您需要将脚本标签放在请求的脚本标签中,首先请求underscore.js和elegate.js,然后在下划线,主干脚本和其余脚本加载之间的脚本中进行_.noConflict().这是原理图版本:
<!DOCTYPE html>
<html>
<head>
<title>Labbo</title>
<script src="underscore.js"></script>
<script src="backbone.js"></script>
<script>
var underscore = _.noConflict();
</script>
<script>
// In it's own script tag for readability
console.log('_ object: ', _);
console.log('"underscore" object: ', underscore);
var m = new Backbone.Model({});
console.log('Dummy backbone model: ', m);
</script>
<!-- Load your other scripts. From here on the '_' global isn't defined -->
<!-- any more. -->
<!-- <script src="your_other_scripts.js"></script> -->
</head>
<body>
Open Developer Tools / Firebug and check the output in the console.
</body>
</html>
(无法将其放在jsfiddle上是因为演示您需要精确控制脚本标记的位置).
标签:backbone-js,underscore-js,conflict,javascript 来源: https://codeday.me/bug/20191208/2088211.html