|
4 | 4 | Extending
|
5 | 5 | =========
|
6 | 6 |
|
7 |
| -Sometimes it can be convenient to add your own methods to a ``Casper`` |
8 |
| -object instance; you can easily do so as illustrated in the example |
9 |
| -below: |
10 |
| - |
11 |
| -:: |
| 7 | +Sometimes it can be convenient to add your own methods to a ``Casper`` object instance; you can easily do so as illustrated in the example below:: |
12 | 8 |
|
13 | 9 | var casper = require('casper').create({
|
14 | 10 | verbose: true,
|
@@ -44,12 +40,7 @@ below:
|
44 | 40 | this.renderJSON(links).exit();
|
45 | 41 | });
|
46 | 42 |
|
47 |
| -But that's just plain old *monkey-patching* the ``casper`` object, and |
48 |
| -you may probably want a more OO approach… That's where the |
49 |
| -``inherits()`` function from the ``utils`` module and ported from |
50 |
| -`nodejs <http://nodejs.org/>`_ comes handy: |
51 |
| - |
52 |
| -:: |
| 43 | +But that's just plain old *monkey-patching* the ``casper`` object, and you may probably want a more OO approach… That's where the ``inherits()`` function from the ``utils`` module and ported from `nodejs <http://nodejs.org/>`_ comes handy:: |
53 | 44 |
|
54 | 45 | var Casper = require('casper').Casper;
|
55 | 46 | var utils = require('utils');
|
@@ -95,23 +86,20 @@ you may probably want a more OO approach… That's where the
|
95 | 86 | this.renderJSON(links).exit();
|
96 | 87 | });
|
97 | 88 |
|
98 |
| -Note the use of the ``super_`` child class property which becomes |
99 |
| -available once its parent has been defined using ``inherits()``; it |
100 |
| -contains a reference to the parent constructor. **Don't forget to call |
101 |
| -``Casper``'s parent constructor!** |
| 89 | +.. note:: |
| 90 | + |
| 91 | + The use of the ``super_`` child class property which becomes available once its parent has been defined using ``inherits()``; it contains a reference to the parent constructor. |
| 92 | + |
| 93 | + **Don't forget to call ``Casper``'s parent constructor!** |
102 | 94 |
|
103 |
| -Note Of course this approach is bit more verbose than the easy |
104 |
| -*monkey-patching* one, so please ensure you're not just overengineering |
105 |
| -stuff by subclassing the ``Casper`` class. |
| 95 | +Note Of course this approach is bit more verbose than the easy *monkey-patching* one, so please ensure you're not just overengineering stuff by subclassing the ``Casper`` class. |
106 | 96 |
|
107 | 97 | Using CoffeeScript
|
108 | 98 | ~~~~~~~~~~~~~~~~~~
|
109 | 99 |
|
110 |
| -If you're writing your casper scripts using |
111 |
| -`CoffeeScript <http://coffeescript.org/>`_, extending casper is getting |
112 |
| -a bit straightforward: |
| 100 | +If you're writing your casper scripts using `CoffeeScript <http://coffeescript.org/>`_, extending casper is getting a bit more straightforward: |
113 | 101 |
|
114 |
| -:: |
| 102 | +.. code-block:: coffeescript |
115 | 103 |
|
116 | 104 | links =
|
117 | 105 | 'http://edition.cnn.com/': 0
|
|
0 commit comments