Y
yawnmoth
Say I have the following:
<script>
var cat = (function() {
var name = "";
function changeName(name) {
this.name = name;
}
function talk() {
alert( this.name + " say meeow!" );
}
return function(name) {
this.name = name;
talk();
}
})();
firstCat = new cat("pursur");
//firstCat.changeName("Bill");
//firstCat.talk(); //alerts "Bill says meeow!"
</script>
Why can I call the talk() function, as defined in the cat variable /
function, from the return function (eg. privately) but not publically?
Also, setting this.name to name doesn't seem to accomplish anything.
What shared variable could I set for talk() to print out the same
value that the return function set?
<script>
var cat = (function() {
var name = "";
function changeName(name) {
this.name = name;
}
function talk() {
alert( this.name + " say meeow!" );
}
return function(name) {
this.name = name;
talk();
}
})();
firstCat = new cat("pursur");
//firstCat.changeName("Bill");
//firstCat.talk(); //alerts "Bill says meeow!"
</script>
Why can I call the talk() function, as defined in the cat variable /
function, from the return function (eg. privately) but not publically?
Also, setting this.name to name doesn't seem to accomplish anything.
What shared variable could I set for talk() to print out the same
value that the return function set?