Not sure why this construction of a class is not working, maybe I'm just calling the function in the wrong way? Here is my code:
function zeros(bits, pattern) {
this.bits = bits;
this.pattern = pattern;
};
zeros.prototype.short = function() {
return this.bits.match(this.pattern)[0].length;
};
heyJude = zeros('1100110011001100000011000000111111001100111111001111110000000000000011001111110011111100111111000000110011001111110000001111110011001100000011', /([0]).*?\1+/);
console.log(heyJude.short());
zeros) and associated object (zeros.prototype). You use it withnew, which creates a new object backed by the object thatzeros.prototypepoints to, then callszeroswiththisreferring to that new object. ES2015 addsclass, which is primarily just more convenient syntax.Zerosrather thanzeros, whereas other functions are (by convention) named with an initial lower-case letter.