views:

21

answers:

2

Hi everybody,

I am not so good with javascript and I do hope you're tougher than me. Here is my problem: I use MicrosoftAjax.cs framework and I use classes like this one :

MyClass =
{
teststring:null,
$constructor: function(test){
teststring = "test";
},
GetInformationFromName : function(inputname, BeginningSeparator, EndSeparator) {
    alert(BeginningSeparator);
    alert(EndSeparator);
},
GetId: function(inputname) {
            return MyClass.GetInformationFromName(inputname,MyClass.teststring, "???");
        }
}

It is a pretty straightforward function where i just want to extract information from a name given in GetId().

My problem is that In GetPerId I can see (in the debugger of visual studio) the value of MyClass.teststring. But when I debug into the call of the function and I arrive in GetInformationFromName, the value passed in parameter is null, whereas a "normal" value does not cause any trouble.

concrete example of what happens (of what i can see) : -> GetId("toto") -> MyClass.GetInformationFromName("toto","&", "???"); -> GetInformationFromName (toto",null, "???")

Would you have any hint about that?

+1  A: 

You're not setting teststring properly in your constructor. Notice how, everywhere else, when calling class variables and methods you need to use MyClass.methodname or MyClass.variablename? In your constructor, you just set teststring="test" when you should be setting MyClass.teststring="test" to override the default value of null.

I don't see a GetPerId method in your code snippet, so I can't explain why VS is displaying the correct value there, but I can tell you that your constructor is setting a local variable of teststring and you're passing a global variable when you call GetInformationFromName in GetID.

Also, I can't see if and when you call $constructor anyway ... so I'm not 100% sure you're even setting the local teststring variable.

EAMann
Thx to you EAMann!
Yoann
A: 

thkx for anyone who share a thought on this one, i found my mistake. I should have use the constructor like this:

$constructor: function(test){
MyClass.teststring = "test";
}

sorry for the bother, hope it helps someone one day...

Yoann