I'm trying to include some namespace into my Javascript API.
Here's what I have so far:
if (!Sample || Sample == "undefined")
var Sample = {};
Sample.SomeApi = {};
Sample.SomeApi.prototype = {
SomeMethod: function() {
alert('some api');
}
};
What's going on here?
When I'm calling Sample.SomeApi.SomeMethod(); // it won't work as it will complain:
Uncaught TypeError: Object #<Object> has no method 'SomeMethod'
(anonymous function)Course:43
onclick
undefinedortypeof Sample === 'undefined'not"undefined".Sample == "undefined"is not going to test if it is undefined, it is going to test whetherSampleequals the string "undefined."Sample == undefinedbut then again the whole undefined is unnecessary, that's what!Sampleis testing for anyway.