Add custom methods to objects: Difference between revisions

From JSXGraph Wiki
(Created page with "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 : <source> ...")
 
(No difference)

Latest revision as of 19:39, 25 June 2015

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