javascript - Accessing object properties within an array -


I am working with paper.js and I want to create a method that dynamically calls each "ball" Imagine object instances each time I have one object:

  var ball = function (point, vector) {this.point = point; This.dampen = .6; This.gravity = 0; This.bounce = -6; Var radius = this.radius = 10 * Math.random () + 30; Var ball = new path Circle ({radius: radius, filling color: palette [math.flur (math.rendum) * palette.lind)]}); This.item = new group ({children: [ball], conversion communication: wrong, position: this.point}); }  

I want to add a new object method for "ball" via "prototype".

  Ball.prototype = {recolor: function () {// do stuff here}} Obviously I have the "fill" of the variable "ball" Need to be able to use the property, but I'm struggling to find a way to do this, so I remembered that I can use the following types:  
  This.item.children [i] .fillColor  

or

  this.item.children [i] .Path.fillColor  < / Pre> 

Although both returns are "undefined" so clearly I'm becoming stupid Hey What would be the correct way to set a prototype method to change the ball object to every other object?

I have made a few changes in your examples and it works for me just to guess my things Happened.

Think about something related to how you defined the group object I tried:

  function group (obj) {this.children = []; This.transformContent = false; This.position = 0.0; $ Expansion (this, OBJ); }  

In addition to this you can try this.item.children.push (ball); .item after starting this.

  & lt; Script src = "https://ajax.googleapis.com/ Ajax / libs / jquery / 1.11.1 / jquery.min.js" & gt; & Lt; / Script & gt;  


Comments