Library
Functions / addFunction
addFunction(name, fn, parent)
Method for adding new methods for object prototypes.
addFunction(string name, function fn)
return: jCanvaScript
Allow to add method to all jCanvaScript objects
Code
<script type="text/javascript">
function start_1(idCanvas)
{
jc('#myCircle_1')
.myFn_1(2);
}
function stop_1(idCanvas)
{
jc('#myCircle_1')
.myFn_1();
}
function onload_1(idCanvas)
{
jc.start(idCanvas,true);
jc.circle(100,100,100,1).id('myCircle_1');
jc.addFunction('myFn_1',
function(arg){
this.scale(arg||Math.random());
});
}
</script>
<canvas id="canvas_1" width="250px" height="265px">
</canvas>
View
addFunction(string name, function fn, string parent)
return: jCanvaScript
Allow to add method to some jCanvascript object prototype (for all circles in the example below).
Code
<script type="text/javascript">
function start_2(idCanvas)
{
jc('#myCircle_2')
.myFn_2(2);
}
function stop_2(idCanvas)
{
try{
jc('#myRect_2')
.myFn_2();
}
catch(e){
alert('method is absent! '+e);
}
}
function onload_2(idCanvas)
{
jc.start(idCanvas,true);
jc.circle(100,100,50,1).id('myCircle_2');
jc.rect(170,100,70,50,1).id('myRect_2');
jc.addFunction('myFn_2',
function(arg){
this.scale(arg||Math.random());
},
'circle');
}
</script>
<canvas id="canvas_2" width="250px" height="265px">
</canvas>
View