Back to Home

Understanding JavaScript Classes: A Practical Guide to Prototypal Inheritance

December 07, 2013

Here is an interesting example for Classes in JS. Classes in JS don’t have a class keyword. ```JavaScript function Range(from, to) { this. from = from; this. to = to; } Range. prototype = { includes: function (x) { return this. from <=x && x <= this. to; }, foreach: function (f) { for(var x= Math. ceil(this. from); x < this. to; x++)f(x); }, toString: function () { return ’(‘+this. from+’.’+this. to+’)’; } }; var r = new Range(4,20); r. includes(5); r. foreach(console. log); console. log(r);


I’m a Principal Engineer at Scalefusion and Django CMS Fellow passionate about solving meaningful problems and pushing tech boundaries. I love reading, listening/playing music, appreciating/making art, and enjoying a good cup of coffee.

Here are some recommendations from my current and past colleagues. You can check out my latest resume and Github profile. You can connect with me on twitter at @vinitkme or drop me an email atmail@vinitkumar.me.

I hope you enjoy reading my essays.

© 2025, Vinit Kumar