Skip to content

Instantly share code, notes, and snippets.

@laurenhavertz
Last active December 21, 2015 02:09
Show Gist options
  • Save laurenhavertz/6233170 to your computer and use it in GitHub Desktop.
Save laurenhavertz/6233170 to your computer and use it in GitHub Desktop.
JS RESOURCES
  • object literals dog = {}

  • constructor notion = var Dog = Action () var Dog = function (name, breed) { this.name = name this.breed = breed this.bark = function() { console.log('ruff ruff'); } }

    kellysDog = new Dog('same, 'richback');
    
    console.log(kellysDog.name); => will print 'Sam'
    kellysDog.bark() => will pribt 'ruff ruff'
    
    Dog.prototype.run = function() {
          console.log('running...')
    }
    
    kellysDog.run(); => will print 'running...'
    
  • prototypical oriented programming: don't have to create a new instance, can create new on the fly - can customize anything and add on

    a = [1,2,3,4]
    
    Array.prototype.first = function  {
          return this[o];
    }
    
    console.log(a.first());
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment