Permalink
Browse files

add an example of calling the constructor with varargs

  • Loading branch information...
1 parent 80a2b5e commit 8e81da3b635c7e2b2a25c9f11343f549c9cfbd42 @jneen committed Jan 9, 2012
Showing with 13 additions and 0 deletions.
  1. +13 −0 examples/varargs.js
View
@@ -0,0 +1,13 @@
+var Breakfast = P(function(breakfast) {
+ breakfast.init = function(bacon, eggs) {
+ this.bacon = bacon;
+ this.eggs = eggs;
+ };
+});
+
+Breakfast('bacon', 'eggs') // => { bacon: 'bacon', eggs: 'eggs' }
+
+// it's just a function. Use `apply` to call it with varargs.
+// NB: this is impossible with traditional JS and the `new` keyword.
+var ingredients = ['bacon', 'eggs'];
+Breakfast.apply(null, ingredients) // => { bacon: 'bacon', eggs: 'eggs' }

0 comments on commit 8e81da3

Please sign in to comment.