Add custom methods to objects

From JSXGraph Wiki
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

JSXGraph objects can be extended to support your own custom method. For example, to add a method called isAlmostOrigin() to the Point objects, write the following code :

 JXG.extend(JXG.Point.prototype,  {
       isAlmostOrigin: function () {
     return Math.abs(this.X()) < 0.5 && Math.abs(this.Y()) < 0.5
   }
 })

 board = JXG.JSXGraph.initBoard('box', { axis:true })
 A = board.create('point', [1, 0], {name:'A'});
 alert(A.isAlmostOrigin()) // false