zspecza / common-tags

🔖 Useful template literal tags for dealing with strings in ES2015+

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Objects call their valueOf methods instead of toString methods.

dragonfire535 opened this issue · comments

When converting objects into strings that have a custom toString method, I've noticed the lib calls valueOf instead. I don't know if this is intentional, but it really is confusing if you aren't expecting this behavior.

console.log(stripIndents`
    ${obj} is cool!
`);

Assuming obj has a valueOf that returns "1" and a toString that returns "2", the valueOf gets called, which in normal template literals is not the case.

I'll investigate this.

Ok, I've got it - it was quite hard to track. I'll prepare a MR, keep your fingers crossed for a fast release!