Want to apply JS AMD specification? It’s not that easy. After dabbling in the AMD specification, I happily added require.js to the page

<! -- AMD specification -->
<script data-main="./js/modules" src="./libs/require.js"></script>
Copy the code

Uncaught Error: Mismatched anonymous define() module



This is a conflict. Require.js does nothing but define a define function. However, this generic name may be used by other JS libraries as well. If a page references many third-party JS libraries, adding require.js to the page may cause a conflict.

In this case, nothing can be changed. Third party JS library, how do you change? The require. Js? You can’t change it. Don’t change.

The solution is to add a floating frame

var require = window.top.require;
//var require = document.getElementById('Frame1').contentWindow.require;
function wind(){
	require(['wind'].function(windjs){
		windjs.go(containerId,viewer,window,Cesium);
	});
}
Copy the code

Complete application AMD specification example: JS application modularity