I have the following error when running the page below:
\"this.testpublic is not a function\"
test = function() { var testprivate = function() {
No, it shouldn't. The function merely defines scope.
When you call foo.bar() then this (inside bar()) is foo. Since there is no explicit foo in this case, it is window by default.
foo.bar()
this
bar()
foo
window
(this is handled differently when the new keyword is in play, but it isn't for that call)
new