Upgrade to Pro — share decks privately, control downloads, hide ads and more …

JS

 JS

nctunba

March 14, 2012
Tweet

More Decks by nctunba

Other Decks in Programming

Transcript

  1. “I had to be done in ten days or something

    worse than JS would have happened.” Brendan Eich
  2. var a = 0.1; // 0.1 a = 010; //

    8 a = 0xab; // 171
  3. var a = [4, 5, [6, 7]]; a[2] // [6,

    7] a.push(7) // a → [4, 5, [6, 7], 7]
  4. var a = [4, 5, , 6]; a.length // 4

    a.toString() // '4,5,undefined,6'
  5. var alice = { name: 'alice', pet: { cat: 'bob',

    fish: ['a', 'b'] } }; alice.pet.fish[0] // 'a'
  6. var a = function () {}, b = 5, c

    = function () { // ... };
  7. var void = function () { // ... }; var

    a = void(); // a → undefined
  8. var chef = function (recipe, ingr) { return recipe(ingr); };

    var pie = function (ingr) { return ingr + ' pie'; }; chef(pie, 'apple'); // 'apple pie'
  9. var grandma = function () { return function () {

    Return 'lol'; }; }; grandma()(); // 'lol'
  10. var addHalf = function (a) { return function (b) {

    return a + b; }; }; var add4 = addHalf(4); add4(5); // 9;
  11. var addFirstThree = function () { return arguments[0] + arguments[1]

    + arguments[2]; }; Func(1, 2, 3, 2, 3); // 6;
  12. var addHalf = function (a) { return function (b) {

    return a + b; }; }; var add4 = addHalf(4); add4(5); // 9;
  13. var Cat = function () { this.name = 'Bob'; };

    var bob = new Cat; Bob.name; // 'Bob'
  14. var Cat = function (name) { this.name = name ||

    'Bob'; }; var bob = new Cat, alice = new Cat('Alice'); bob.name; // 'Bob' alice.name; // 'Alice'
  15. var Cat = function () { this.name = 'Bob'; this.miaou

    = function () { return this.name }; }; var bob = new Cat; bob.miaou(); // 'Bob'
  16. var Cat = function () { this.name = 'Bob'; };

    Cat.prototype.miaou = function () { return this.name }; var bob = new Cat; bob.miaou(); // 'Bob'