Skip to content

Instantly share code, notes, and snippets.

View chunkybyte's full-sized avatar
💭
Keep Calm. Eat Rasmalai.

Ekansh Kothiyal chunkybyte

💭
Keep Calm. Eat Rasmalai.
View GitHub Profile
@chunkybyte
chunkybyte / simple-duck-punching.js
Created June 16, 2020 20:25
Simple Duck Punching Example in Vanilla JavaScript
// Duck Punching in JavaScript
const sentence = 'The quick brown fox jumps over the lazy dog. If the dog barked, was it really lazy?';
const legacyIndexOf = String.prototype.indexOf;
// Extending the indexOf functionality to return the last occurence of the searchValue
String.prototype.indexOf = function (searchValue, fromIndex, getLastIndexFlag = false) {
if (!getLastIndexFlag) {
return legacyIndexOf.call(this, searchValue, fromIndex);