Skip to content

Instantly share code, notes, and snippets.

@MoOx
Last active August 26, 2018 16:16
Show Gist options
  • Save MoOx/336b9f0654538e5d5763 to your computer and use it in GitHub Desktop.
Save MoOx/336b9f0654538e5d5763 to your computer and use it in GitHub Desktop.
es5 string vs es6 template string
Renderer.prototype.image = function(href, title, text) {
var out = '<img src="' + href + '" alt="' + text + '"';
if (title) {
out += ' title="' + title + '"';
}
out += this.options.xhtml ? '/>' : '>';
return out;
};
Renderer.prototype.image = function(href, title, text) {
return (
`<img src="${href}" alt="${text}"` +
`${title ? ` title="${title}"` : ``}` +
`${this.options.xhtml ? "/>" : ">"`
)
}
@jonathanKingston
Copy link

Doesn't this work:

Renderer.prototype.image = function(href, title, text) {
  return `
    <img src="${href}" alt="${text}"
    ${title ?  ` title="${title}"` : ``}
    ${this.options.xhtml ? "/>" : ">"}
  `;
}

?

@MoOx
Copy link
Author

MoOx commented May 18, 2015

Yes but it add extra whitespace I don't want :)

@dondish
Copy link

dondish commented Aug 26, 2018

it is not an extra whitespace, it renders this as \n\t (CRLF) which is on Windows.
if you try and print the literal it will be normal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment