Ashkan Mobayen Khiabani Ashkan Mobayen Khiabani - 1 year ago 94
Javascript Question

using a group of functions as a prototypes in javascript

We use like

String.prototype.EndsWith = function(){ ... }

What I'm trying to do is to have several functions and be able to add them to Number, String, ... or anything else, I'm trying to find a way that has a group of functions and I can just add one prototype to an object letting it access all of these functions

Answer Source

You can do something like this.

String.prototype.myMethods = function(){
  var self = this; 
  return {
    endsWith: function(str){
      if (self.substr(str.length-1).localeCompare(str)){
        return true; 
      return false; 

var str = "String"; 


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download