Reputation: 105
I guess it's really a newbie error, but I can't get it running. I have an "calculator" object t, which contains a lot of function to calculate values. I need to use these functions from my "calculator" object to get some values in another function. I striped it down to the following, but I get an TypeError exceptio when I call the t.hello() method. Any ideas?
var t = new T();
two();
function T() {
function hello() {
alert("hello");
}
}
function two() {
t.hello();
}
Upvotes: 0
Views: 43
Reputation: 1295
Try this,
var t = new T();
two();
function T() {
this.hello = function () {
alert("hello");
}
}
function two() {
t.hello();
}
see this : http://jsfiddle.net/4Cc4F/2/
Upvotes: 0
Reputation: 25882
function hello
is in local scope of T
.
define T
like this.
function T() {
this.hello = function() {
alert("hello");
}
}
Upvotes: 1