class vs proto

Edit on GitHub

cvcv

Setup

class R1{
	constructor(text){
		this.a = text
	}
	read(method){
		return this.text
	}
	write(text){
		this.a = text
	}
}

function R2(text){
	this.a = text
}
R2.prototype.read(method){
	return this.text
}
R2.prototype.write(text){
	this.a = text
}

Tests

  • class

    var a = new R1;
  • proto

    var b = new R2;