<!DOCTYPE html>
<html>
<head>
<script data-main="js/main.js" src="js/lib/require.js"></script>
</head>
<body>
</body>
</html>
require.config({
baseUrl: 'js',
shim: {
'mylib' : ['util'],
}
});
require(['util','mylib'], function(util) {
var result = util.add(1, 2);
console.log('1 + 2 = ' + result);
console.log(hello("Fan"));
console.log(sum(1,2,3,4,5));
});
define(function() {
return {
add: function(a, b) {
return a + b;
}
};
});
function hello(name) {
return "Hello " + name + " san!";
}
function sum() {
var sum = 0;
util = require('util');
console.log(util);
for(i = 0; i < arguments.length; i++) {
sum = util.add(sum, arguments[i]);
}
return sum;
}
実行結果
HTML#Knockout