Monday 15 June 2015

javascript - Access object properties after they are assigned by another function -


I'm new to JavaScript, and I'm learning how to use OP principals in specifying object properties I'm stuck and access them later. Suppose I have this function that gives an object the property for "car".

  assignmentProp () {Car.size = "small"; Car.cost = "expensive"; }   

The object car is due to empty properties because they are assigned from the function.

  var car = {size: "", cost: "", return size: function () {return.size; }, Returncast: function () {return.cost; },}   

Now, I want to call the function which specifies the value, and then using the properties of the car. I tried to do this, but it was clearly unsuccessful:

  function accesspops () {assignpops (); Console.log (Car.returnSize ()); Console.log (Car.returnCost ()); }   

Any help would be appreciated. I think it may have to be done with constructor or prototype, but because JavaScript has many ways of creating custom objects, the documentation is very confusing. Edit: By "Fail" I mean that it edits the blank space instead of the new allocated value Edit: I tried to do it the same way, and as a result resulted in the same result met.

There are some errors in your code:

  var car = < / Code>  

And if you see this Bela: it works as expected.

Full code:

  assignprop () {Car.size = "small"; Car.cost = "expensive"; } Var car = {size: "", cost: ""} function accesspops () {assignpops (); Console.log (Car.size); } Assignpops (); AccessProps ();    

No comments:

Post a Comment