News for hackers. Stuff that matters.
Re:Prototypes Are Not Classes by colept on Sunday January 19, 2014 @11:11PM (#7087507)
It felt like the author was using the post as a cathartic persuasion for why prototypes differ from classes. JavaScript functions are a prototype of a class. Prototyping in JavaScript is an analog to class extensions, with elaborate definitions for private/protected variables. It's a debate over semantics and syntax, and it's useless because the analog to a object oriented class can be done with JavaScript's syntax.

  function MyClass()
  {
  	var self = this;
  	var privateVar = 0;
  	this.getPrivate = function() { return privateVar; }
  	this.setPrivate = function(val) { privateVar = parseInt(val); // restrict type }
  	this.publicVar = "Hello World";
  }

  MyClass.prototype.extension = function() {
  	// Here 'this.publicVar' can be set but 'this.privateVar'
   	// and 'privateVar' are not a valid references.
  }
Long story short, the class analog is semantically no different than the JavaScript prototype when done correctly.
Re:Prototypes Are Not Classes by raganwald on Monday January 20, 2014 @12:33AM (#7087767)
Encapsulating instance state us not the point, encapsulating the class behaviour is the point. So, if you can make the prototype itself private and modify the prototype with class methods, you have something that prototypes by themselves do not express.

The analogy is not to a private instance variable in Ruby, the analogy is to a class method in Ruby Dutch as define_method.