In your code, init
is not available to be called externally. I believe you're looking for something like this:
(function (document,window) {
var shelf = window.shelf = function (foo) {
this.init = function () {
console.log("in init" + foo);
};
alert("in shelf.js "+ foo + "type" + typeof this.init);
};
})(document, window);
var api = new shelf("1234");
api.init();