在p5网站上给出的示例中,使用了一个我不太了解的参数(我认为这是正确的术语)。非常感谢您需要完整的代码,该代码可从上面的链接获得。任何关心解释的人将不胜感激。
Particle.prototype.display = function(other) {
stroke(0, this.lifespan);
fill(0, this.lifespan/2);
ellipse(this.position.x,this.position.y, 8, 8);
// If we need to draw a line
if (other) {
line(this.position.x, this.position.y, other.position.x, other.position.y);
}
}
函数可以带参数。参数写在括号中。在此示例中,抛物线为other
。在上面的示例中。“其他”是另一个对象。例如Particle.prototype.display(someobject);
我希望这是可以理解的。
var div = document.getElementById("test");
test(true);
test(false);
function test(parameter){
if(parameter){
div.innerHTML += "Hello"
}else{
div.innerHTML += " World!"
}
}
<div id="test"></div>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句