javascript - Why type error is appearing? -


i'm learning javascript , playing functions when encountered error when running code:

var arrayofobjects = [{   prop1: "a",   prop2: "b" }, {   prop1: "c",   prop2: "d" }];  function testfunc(arrayofobjects) {   (var = 0; < arrayofobjects.length; i++) {     arrayofobjects[i].newfunctionprop = function() {       console.log("hello!");     };   } }  arrayofobjects[0].newfunctionprop(); 

the error is:

typeerror: arrayofobjects[0].newfunctionprop not function 

can explain why property not function when assigned function expression property in loop before?

as denys séguret mentioned, 1 need run testfunc testfunc(arrayofobjects); creates property needed.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -