diff --git a/docs/basics.md b/docs/basics.md index 9feac693de..af13a6d624 100644 --- a/docs/basics.md +++ b/docs/basics.md @@ -62,6 +62,8 @@ var MyView = Mn.View.extend({ }); ``` +[Live example](https://jsfiddle.net/marionettejs/k93pejyb/) + When we instantiate `MyView`, each instance will be given a `.bg-success` class with a `myRegion` region created on the `.my-region` element. @@ -99,20 +101,19 @@ var MyView = Mn.View.extend({ }, alert: function() { - window.alert('model changed'); + console.log('model changed'); } }); ``` +[Live example](https://jsfiddle.net/marionettejs/nn1754fc/) + As we can see, almost all of the attributes here can be worked out dynamically. In most cases, Marionette will call the function once at instantiation, or first render, and preserve the value throughout the lifetime of the View. There are some exceptions to this rule - these will be referred to with their respective documentation. -There are some exceptions to this general rule that will be documented in the -relevant places. - ### Function Context When using functions to set attributes, Marionette will assign the instance of @@ -189,9 +190,11 @@ var view = new MyView({ foo: 'some text' }); -view.checkOption(); // prints 'some text' +console.log(view.checkOption()); // prints 'some text' ``` +[Live example](https://jsfiddle.net/marionettejs/6n02ex1m/) + ### The `getOption` Method To access an option, we use the `getOption` method. @@ -213,6 +216,8 @@ var myView = new MyView({ }); ``` +[Live example](https://jsfiddle.net/marionettejs/ekvb8wwa/) + This only works for custom options - arguments that belong to the standard Backbone/Marionette attributes, such as `model` and `collection`, are not accessible via `getOption` and should be accessed as just `view.model` or @@ -246,6 +251,8 @@ console.log(myObject.something); console.log(myObject.getOption('another')); ``` +[Live example](https://jsfiddle.net/marionettejs/ub510cbx/) + In this example, `model` and `something` are directly available on the `MyObject` instance, while `another` must be accessed via `getOption`. This is handy when you want to add extra keys that will be used heavily throughout the