Login Register

[fixed] it say "is not a function"

Hi,

Please help to solve the follwoing strange issue.
I create a function, then want use in a html. My class is ok, but function is not OK.The error say:" It is not a function".Please see my code

dojo.provide("Demo.ApplicationManager");
Demo.ApplicationManager.getConfig = function(){
alert("Demo.ApplicationManager.getConfig");
};
var kkk=Demo.ApplicationManager.getConfig;
dojo.declare("Demo.ApplicationManager",null,{
constructor:function(){
},
start:function(){
alert("start");
kkk(); // it is ok
//Demo.ApplicationManager.getConfig() ----- it is not ok
}
});

I can new Demo.ApplicationManager(), but I cannot call Demo.ApplicationManager.getConfig().But if I use var kkk=Demo.ApplicationManager.getConfig, then I can call kkk()

I don't know why.

Thanks!
Gary

maybe the 'kkk' var is a

maybe the 'kkk' var is a stored reference to that function, and the dojo.declare() is somehow clobbering the real function? seems a long shot though.

also, what happens if you try "this.getConfig()" in your start() method?

It not work wen I try

It not work wen I try "this.getConfig()".

I have look through dojo source. Define a function is a simple, it works. But why my code not wor?

For example
dojo.provide("dojo.date");
dojo.date.getDaysInMonth = function(/*Date*/dateObject){....}

dojo.provide("dojo.string");
dojo.string.pad = function(/*String*/text, /*int*/size, /*String?*/ch, /*boolean?*/end){..}

And so on.

I am successed after move the code to the after of declare

I just change the code, put the function defination after declare
dojo.declare("Demo.ApplicationManager",null,{});
Demo.ApplicationManager.getConfig = function(){
alert("Demo.ApplicationManager.getConfig");
};

But I really don't know why? Any body can give some idea?

maybe dojo.declare() nulls

maybe dojo.declare() nulls out the ApplicationManager namespace during it's init. Then, you define it after that and works because the Demo.ApplicationManager is a function (object) with a getConfig function (but not part of the declared class)