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.
(function init () {function circle (obje) {this.radius = 0; this.fillColor = 0; $ Extend (this, obg);} function group (obj) {this.children = []; this.transformcontent = false; this.position = 0.0; $ .extend (this, obj);} 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 Circle ({Triz (Radius, fill: 10}); this.item = new group ({children: [ball], transformContent: false, position: point});} Ball.prototype = {recolor: function () {// do stuff Here var f = this.item.children [0] .fillColor; Console.log ("f:" + f)}} var b = new ball (6,7); b.recolor ();}) ();
& lt; Script src = "https://ajax.googleapis.com/ Ajax / libs / jquery / 1.11.1 / jquery.min.js" & gt; & Lt; / Script & gt;
Comments
Post a Comment