Sachin Kadam Sachin Kadam - 5 months ago 12
Javascript Question

Inline input to custom function

I like to implement reverse() method on string.
But input should be inline. such as,

"December".reverse();

function reverse(){
return reverse("").join(" ");
}

Answer

Try this ?

String.prototype.reverse = function() {
  return this.split("").reverse().join("");
}

"test".reverse() // tset

Don't forget to define the propotype before use it

Comments