0

Nope, the title is not an enigma.

I have :

obj = {
    NaNException:function(message=''){
        this.message=message;
    },
    input:{
        integer:function(a){
            var b = prompt(a);
            if (isNaN(parseInt(b, 10)))
                throw new this.NaNException();
            else
                return b;
        }
    }
}

so, in NaNException:function(){ }, this is expected to be NaNException, but in integer, it is expected to be obj... which interpretation is the good one? And what can I do with the wrong one to have the expected result ?

Thanks in advance.

Algorythmis
  • 552
  • 6
  • 18
  • obj, so global `obj.message` is the same object as `this.message` in your scope – Mark Schultheiss Oct 03 '16 at 20:12
  • 1
    It's impossible to say which value `this` will have because the value depends on how the functions are called. The only thing we can say is that since the function is called `this.NaNException`, `this` inside `NaNException` will refer to whatever `this` refers to in `integer`. – Felix Kling Oct 03 '16 at 20:38

0 Answers0