javascript - Cannot Set Property ... of undefined --- bizarre -


i'm getting bizarre error in chrome... check out screenshot below.

i define record using object literal syntax.

i try setting "id" property , exception.

i've tried both :

record['id'] = 'wtf'; 

and also

record.id = 'wtf'; 

i use type of syntax on place in script.... going on here ? bug in chrome ?

alt text

edit : i've solved problem now, i'm still not sure why happening. moved definition of record occur outside of if block. know occurring ? thought variable declarations scoped function , therefore shouldn't issue.

the problem dl less or equal zero, statement initializes record doesn't executed. indentation, looks intended both statements part of if block, no braces, record['id'] = 'wtf'; statement gets executed no matter what.

by moving variable initialization outside if statement, forced happen in case , moved assignment inside if block (which, i'm assuming wanted).

probably better way solve adding braces this:

if (dl > 0) {     var record = {};      record.id = 'wtf'; } 

unless want initialize record in both cases.

you correct variable declarations being scoped function, assignment doesn't happen until point in code. record in scope, still had default value of undefined because hadn't assigned yet.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -