Add custom methods to objects

From JSXGraph Wiki
Revision as of 19:39, 25 June 2015 by Nicolas.adenis.lamarre (talk | contribs) (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> ...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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