Vic Sowers wrote:
OK, what I really want is:
function MyObject(arg) {
var private = arg;
this.public = 0;
MyFunc = function () {return private*this.public);
I guess you want
this.MyFunc = .. }
If you want to have something like private members in JavaScript 1.x
then the suggested way to achieve that is using an inner function and
exploiting closures as above but you need then to be aware that indeed
any creation of new MyObject() creates its own inner function object so
that approach is much more memory intensive as using public members and
share methods as function properties of the prototype. It is up to you
to decide how much objects you need te create and whether private
members are improving your code.
--
Martin Honnen
http://JavaScript.FAQTs.com/