Mercurial > js4py
comparison core-javascript/simple-classes.rst @ 207:29c7fe19aeb5
Mark inline code using duble backticks
| author | Radomir Dopieralski <radomir.dopieralski@allegro.pl> |
|---|---|
| date | Thu, 17 May 2012 11:24:48 +0200 |
| parents | fef162a89a47 |
| children |
comparison
equal
deleted
inserted
replaced
| 206:a2fb6c95d156 | 207:29c7fe19aeb5 |
|---|---|
| 5 inheritance. Almost all object-oriented languages have classes and | 5 inheritance. Almost all object-oriented languages have classes and |
| 6 instances, but JavaScript has neither. This will be explained later, | 6 instances, but JavaScript has neither. This will be explained later, |
| 7 along with a discussion of the consequences. | 7 along with a discussion of the consequences. |
| 8 | 8 |
| 9 For now our focus is on getting going with object-oriented | 9 For now our focus is on getting going with object-oriented |
| 10 programming. The easiest way to do this is via create. | 10 programming. The easiest way to do this is via ``create``. |
| 11 | 11 |
| 12 | 12 |
| 13 Definition | 13 Definition |
| 14 ---------- | 14 ---------- |
| 15 | 15 |
| 16 Here's a factory function that creates classes. It returns a function | 16 Here's a factory function that creates classes. It returns a function |
| 17 called *cls*, which in turn when called returns instances. At it's | 17 called ``cls``, which in turn when called returns instances. At it's |
| 18 heart is *create*, and also *apply* and *arguments*, which we've not | 18 heart is ``create``, and also ``apply`` and ``arguments``, which we've not |
| 19 seen before). | 19 seen before). |
| 20 | 20 |
| 21 .. literalinclude:: /core-javascript-work/library.js | 21 .. literalinclude:: /core-javascript-work/library.js |
| 22 :language: javascript | 22 :language: javascript |
| 23 :start-after: start SimpleClass | 23 :start-after: start SimpleClass |
| 35 | 35 |
| 36 | 36 |
| 37 Fruit example | 37 Fruit example |
| 38 ------------- | 38 ------------- |
| 39 | 39 |
| 40 Here's an example of the use of *SimpleClass*. There's a bug in it, | 40 Here's an example of the use of ``SimpleClass``. There's a bug in it, |
| 41 and I've changed the test so it passes. Can you find the bug and fix | 41 and I've changed the test so it passes. Can you find the bug and fix |
| 42 the example? | 42 the example? |
| 43 | 43 |
| 44 .. literalinclude:: /core-javascript-work/test_library.js | 44 .. literalinclude:: /core-javascript-work/test_library.js |
| 45 :language: javascript | 45 :language: javascript |
