試圖學習require.js - 我有一個主要要求加載一個簡單的函數來檢索瀏覽器窗口的大小。我得到未捕獲的錯誤:不匹配的匿名define()模塊:[object Object] http://requirejs.org/docs/errors.html#mismatch錯誤。學習JavaScript的要求
這裏是main.js和helper \ getwindowsize.js - 我不知道我在做什麼錯。
main.js
//determine how much space is available within the browser window
var viewportWidth;
var viewportHeight;
require(["helper/getwindowsize"], function(GetBrowserWindowSize) { getwindowsize.GetBrowserWindowSize(); });
GetBrowserWindowSize(viewportWidth, viewportHeight);
document.write('<p>Your viewport width is '+viewportWidth+'x'+viewportHeight+'</p>');
幫手\ getwindowsize.js
define(function()
{
console.log("Function : GetBrowserWindowSize");
return
{
GetBrowserWindowSize: function(viewportWidth, viewportHeight)
{
// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
if (typeof window.innerWidth != 'undefined')
{
viewportWidth = window.innerWidth, viewportHeight = window.innerHeight
}
// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth !=
'undefined' && document.documentElement.clientWidth != 0)
{
viewportWidth = document.documentElement.clientWidth, viewportHeight = document.documentElement.clientHeight
}
// older versions of IE
else
{
viewportWidth = document.getElementsByTagName('body')[0].clientWidth, viewportHeight = document.getElementsByTagName('body')[0].clientHeight
}
}
}
});
hrmmm ..現在我有2個錯誤..除了沒有定義getwindowsize之外,仍然收到常規http://requirejs.org/docs/errors.html#mismatch錯誤,我簡化了這兩個腳本以查看是否我可以得到任何東西,但仍然失敗 – Bixel
'main.js''require([「helper/getwindowsize」],function(GetBrowserWindowSize) { var size = new GetBrowserWindowSize(); console.log(size); });'' – Bixel
'getwindowsize.js'定義(函數() { 返回 { GetBrowserWindowSize:功能() { 變種大小= 100; 退貨尺寸; } } });' – Bixel