0
*Effen* is a jQuery plugin that supports Concrete Javascript. Concrete Javascript is a pattern in which the state and behavior of your domain are attached directly to DOM elements. This differs from MVC, where domain behavior is isolated from the view. Concrete Javascript is draws inspiration from Self's Morphic UI framework.
0
@@ -24,7 +24,7 @@ That's all there is to it. But there are some subtle details to bear in mind:
0
$('div').fn({ foo: function() {} });
0
$('div.special').fn({ foo: function() {} });
0
-
The latter takes precedence because it appears last--NOT because the selector is more specific. This may be changed in future releases.
0
+
The latter takes precedence because it appears last--NOT because the selector is more specific. This may be changed in future releases.
0
## An in-depth example of Concrete Programming ##
0
@@ -48,7 +48,7 @@ Suppose we have the following HTML code, representing a Script that has many Sce
0
-### Let's start with some simple CRUD operations. To
"create" a scene, we POST to the url: ###
0
+### Let's start with some simple CRUD operations. To
*create* a scene, we POST to the url: ###
0
@@ -88,15 +88,12 @@ We'd also like to bind the <Backspace> key from within the Dialog characte
0
$.delete($(this).attr('url'), $(this).remove);
0
- return $(this).fn('character').fn('isBlank') && $(this).fn('text').fn('isBlank');
0
+ return $(this).find('input[@name=character]').val() == "" &&
0
+ $(this).find('input[@name=text]').val() == "";
0
-Using the technique shown in the previous section, the character input is given a reference to the dialog, and the dialog a reference to the character and text (omitted here). `isBlank` is defined on character and text thusly:
0
- isBlank: function() { return $(this).val() == '' }
0
+Using the technique shown in the previous section, the character input is given a reference to the dialog (omitted here).
0
### Polymorphism in Concrete Javascript ###
0
@@ -120,4 +117,6 @@ At this point, we may notice that the definition of delete is the same for Scene
0
if ($(this).fn('isBlank'))
0
$.delete($(this).attr('url'), $(this).remove);
0
\ No newline at end of file
0
+So now we have achieved a kind of polymorphism: Both Scenes and Dialogs respond to `isBlank`, though each have differing implementations. Each has a different `url` attribute and each (given that they are DOM objects) can be `removed`. Given that they conform to the same interface, we can implement a generic `delete` method for both of them.
0
\ No newline at end of file
Comments
No one has commented yet.