0

I have a scenario where in I want to print custom message on log of some method reference.

Say I have a function sum(){} now on console.log(sum); I want to log a custom message on console. How can we achieve that?

4

1 Answer 1

1

Like this

var sum = function(){};

sum.toString = function(){ return 'my custom message'; };

console.log(sum);

Sign up to request clarification or add additional context in comments.

1 Comment

This answers my questions to some extent. :)

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.