Javascript functions objects
Hi,
Can anyone explain why this is?
functions can be declared in the constructor or in the prototype or on the object after the object has been initialised.
functions can not be declared on the object previous to initialisation, it is not available after iniaialisation.
e.g.
<script type="text/javascript">
var Person = function () {
this.ctx = 'this is some other stuff'; // Public ;
var stuff = 'this is some stuff'; // Private
this.getThisSuff = function () { // this works
return stuff;
};
};
Person.getMyOtherStuff = function () { // this doesnt work
return (function () {return this.ctx;})();
};
Person.prototype.getMyStuff = function () { // this works
return this.ctx;
};
Person.StuffHolder = 'more stuff'; // this works
var p = new Person();
alert('1 ' + p.getThisSuff()); // works
alert('2 ' + p.getMyStuff()); // works
alert('3 ' + p.getMyOtherStuff()); // dont work, why so?
</script>