Domanda

I'd like to create a tryParse() static method for Date class. How can I do that?

Date.prototype.tryParse = function (value, result) {
    // ... Code ...
};

This adds an instance method, not a static class method. Any idea?

È stato utile?

Soluzione

First: you really, really shouldn't. To avoid collisions and incompatibilities, it's really much, to keep that sort of method in a namespace specific to your project:

var myUtils = {};
myUtils.tryParseDate = function(…) {…}

BUT! If you really, really, want to:

Date.tryParse = function(…) {…}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top