Unable to set property ... from undefined --- weird

I get a strange error in Chrome ... check the screenshot below.

I define a record using the object literal syntax.

I am trying to set the id property and get an exception.

I tried both:

record['id'] = 'wtf';

and

record.id = 'wtf';

I use this type of syntax throughout my script .... what can happen here? Is this a bug in Chrome?

alt text

EDIT: At the moment, I have solved the problem, but I'm still not sure why this is happening. I moved the definition of write to write outside the if block. Does anyone know what could happen? I thought that all variable declarations are bound to a function, and therefore this should not be a problem.

+5
source share
2 answers

, dl , , record, . , , , if, , record['id'] = 'wtf'; , .

if, if (, , , ).

, - :

if (dl > 0) {
    var record = {};

    record.id = 'wtf';
}

record .

, , , . record , - undefined, .

+15

, , . , ? , alert(record), ? ?

0

All Articles