-1

In code why following line is used, since it's not creating emails from collection list.

Ambiguous Code Line: "return {$item}$@{ this.domain }"

var object = {

    collection: ["kapil", "abdul", "shiv"],
    domain: 'infobeans.com',
    method: function method() {
        return this.collection.map(item => {
            //return item + '@' + this.domain;
            return `{$item}$@{ this.domain }`
        });
    }
};

console.log(object.method());
James Dewes
  • 387
  • 4
  • 22
Kapil Yadav
  • 650
  • 1
  • 5
  • 29
  • https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals – Weedoze Dec 07 '16 at 08:59
  • you know what that return statement will return? ... `{$item}$@{ this.domain }` ... perhaps you mean `${item}@${this.domain}` – Jaromanda X Dec 07 '16 at 09:01
  • I am wathcing ES2015 tutorials and it's working there but when i tried same thing on my local it's just printing expression in console. That's why i created this question. What can be a reason for this ? – Kapil Yadav Dec 07 '16 at 09:02
  • 1
    because you've swapped { an $, and later, $ and @ - thinking the order is unimportant - see the correct order and how it works as advertised – Jaromanda X Dec 07 '16 at 09:03

1 Answers1

1
var object = {

    collection: ["kapil", "abdul", "shiv"],
    domain: 'infobeans.com',
    method: function method() {
        return this.collection.map(item => {
            //return item + '@' + this.domain;
            return `${item}@${ this.domain }`
        });
    }
};

console.log("object.method",object.method());
anshuVersatile
  • 2,030
  • 1
  • 11
  • 18