[Pas2js] Just sharing the class helpers importance

silvioprog silvioprog at gmail.com
Sat Dec 22 06:55:53 CET 2018


Hi dudes.

Many JavaScript libraries allows to use plugins (or modules) to extend
their APIs. In general, such plugins just extends their object(s) prototype.

For example, the jsPDF doesn't allows to auto generate tables easily by
itself, but we can change it using a plugin like this jsPDF-AutoTable plugin
<https://github.com/simonbengtsson/jsPDF-AutoTable>, and the table
generation is a piece of cake. ☺ This link
<https://simonbengtsson.github.io/jsPDF-AutoTable/> contains a lot of new
features which can be added to make it easy to generates tables in our PDFs.

"Ok guy, but and the class helpers?". 😎 The class helpers will extend our
class methods, something like extending the JS' prototype. Take a look at
this small example below:

uses
  jsPDF,
  jsPDF_AutoTable;

var doc := TjsPDF.new('p', 'pt');
doc.autoTable(columns, rows);
doc.save('table.pdf');

The method "autoTable()" will be "magically" added into the class "TjsPDF"
by the class helper "TjsPDFAutoTable" declared in the "jsPDF_AutoTable"
(plugin) unit. 😃

In that context, the class helpers will fit like a glove!

-- 
Silvio Clécio
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/pas2js/attachments/20181222/ce2d96f4/attachment.html>


More information about the Pas2js mailing list