for 2, you don't have to. for all your methods it's really
unnecessary to fully reference since these are all methods instead of
pure functions.
http://jsfiddle.net/rH9Ef/1/ In fact, that's why
dependentObservable has that second parameter: to allow you to set
what "this" is (a Function.prototype.bind wrapper if you will).
for 1, if there's anything you want to exist only privately but you
want to access later, you'd hide that inside a closure (I assumed "eh"
means you wished that was private)
http://jsfiddle.net/rH9Ef/2/
properties are a little more tricky, because you then need an "own"
method instead of a prototypal method for each function that accesses
them since the function needs to close over the value.
//works
function MyObj (name) {
var private = name;
this.publicFunc = function () {
return private;
}
}
//doesn't work as private will change with each new class
(function(){
var private;
function MyObj (name) {
private = name;
}
MyObj.prototype.publicFunc = function () {
return private;
};
}());
but I can say that my idealism about separation of privates has
lessoned as I've dealt with debugging and just prepending _ to your
private properties and methods is really a lot easier, especially as
you can then access them from firebug directly without having a
breakpoint set in the right spot. Obviously there are use cases where
you must keep privates private, but in most cases I'm getting less
religious about it and moving to convention instead.