Skip to content

Instantly share code, notes, and snippets.

@erikpantzar
Last active January 17, 2016 16:31
Show Gist options
  • Select an option

  • Save erikpantzar/b36bd76eea169c9a13fb to your computer and use it in GitHub Desktop.

Select an option

Save erikpantzar/b36bd76eea169c9a13fb to your computer and use it in GitHub Desktop.
Why Classes in js? Who cares, why is it good, How do I use it beneficially?

Article: "Does Javascript need Classes?"

https://www.nczonline.net/blog/2012/10/16/does-javascript-need-classes/

Protype and inheretence

https://msdn.microsoft.com/en-us/magazine/ff852808.aspx

syntax for classes in ecmascript4

http://stackoverflow.com/questions/387707/what-techniques-can-be-used-to-define-a-class-in-javascript-and-what-are-their

  // Define a class like this
  function Person(name, gender){
     // Add object properties like this
     this.name = name;
     this.gender = gender;
  }

  // Add methods like this.  All Person objects will be able to invoke this
  Person.prototype.speak = function(){
      alert("Howdy, my name is" + this.name);
  };

  // Instantiate new objects with 'new'
  var person = new Person("Bob", "M");
  
  // Invoke methods like this
  person.speak(); // alerts "Howdy, my name is Bob"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment