7

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?

1
  • Yep. Sorry, I didn't remove the typings when writing the question. Correcting now. Commented Apr 1, 2014 at 23:22

1 Answer 1

12

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(…) {…}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.