diff --git a/documentation/coffee/constructor_destructuring.coffee b/documentation/coffee/constructor_destructuring.coffee new file mode 100644 index 0000000000..53c4b39a0d --- /dev/null +++ b/documentation/coffee/constructor_destructuring.coffee @@ -0,0 +1,4 @@ +class Person + constructor: (options) -> + {@name, @age, @height} = options + diff --git a/documentation/coffee/switch_with_no_expression.coffee b/documentation/coffee/switch_with_no_expression.coffee new file mode 100644 index 0000000000..08160199f9 --- /dev/null +++ b/documentation/coffee/switch_with_no_expression.coffee @@ -0,0 +1,8 @@ +score = 76 +grade = switch + when score < 60 then 'F' + when score < 70 then 'D' + when score < 80 then 'C' + when score < 90 then 'B' + else 'A' +# grade == 'C' diff --git a/documentation/index.html.erb b/documentation/index.html.erb index 522ad10849..e29ea8574f 100644 --- a/documentation/index.html.erb +++ b/documentation/index.html.erb @@ -761,6 +761,11 @@ Expressions Destructuring assignment can even be combined with splats.
<%= code_for('patterns_and_splats', 'contents.join("")') %> ++ Destructuring assignment is also useful when combined with class constructors + to assign propeties to your instance from an options object passed to the constructor. +
+ <%= code_for('constructor_destructuring', 'contents.join("")') %>@@ -818,6 +823,11 @@ Expressions
<%= code_for('switch') %> ++ Switch statements can also be used without a control expression, turning them in to a cleaner alternative to if/else chains. +
+ <%= code_for('switch_with_no_expression') %> +Try/Catch/Finally diff --git a/documentation/js/constructor_destructuring.js b/documentation/js/constructor_destructuring.js new file mode 100644 index 0000000000..06c7d4877e --- /dev/null +++ b/documentation/js/constructor_destructuring.js @@ -0,0 +1,12 @@ +// Generated by CoffeeScript 1.3.3 +var Person; + +Person = (function() { + + function Person(options) { + this.name = options.name, this.age = options.age, this.height = options.height; + } + + return Person; + +})(); diff --git a/index.html b/index.html index 426cc0401b..95d299aa97 100644 --- a/index.html +++ b/index.html @@ -1735,6 +1735,37 @@
+ Destructuring assignment is also useful when combined with class constructors + to assign propeties to your instance from an options object passed to the constructor. +
+class Person + constructor: (options) -> + {@name, @age, @height} = options + +
var Person; + +Person = (function() { + + function Person(options) { + this.name = options.name, this.age = options.age, this.height = options.height; + } + + return Person; + +})(); +