How do I call functions of an object inside the same object?
Posted
by Roly
on Stack Overflow
See other posts from Stack Overflow
or by Roly
Published on 2010-04-18T07:30:52Z
Indexed on
2010/04/18
7:33 UTC
Read the original article
Hit count: 275
javascipt
|object-oriented-design
I have the following Javascript code
add_num = {
f: function(html, num) {
alert(this.page);
},
page : function() {
return parseInt(this.gup('page'));
},
gup : function(name) {
name = name.replace(/[\[]/,'\\\[').replace(/[\]]/,'\\\]');
var regex = new RegExp('[\\?&]'+name+'=([^&#]*)');
var results = regex.exec(window.location.href);
if(results == null)
return '';
else
return results[1];
}
}
But when I call add_num.f() what I get from alert() is the actual code of page. That is, it returns
function() {
return parseInt(this.gup('page'));
}
I was expecting a numeric value and not any code at all.
© Stack Overflow or respective owner