trying to learn require.js - I have a main with require loading a simple function to retrieve the browser window size. I am getting the Uncaught Error: Mismatched anonymous define() module: [object Object] http://requirejs.org/docs/errors.html#mismatch error.
here is both main.js and helper\getwindowsize.js - I don't know what I am doing wrong.
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>');
helper\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
}
}
}
});