Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xgqfrms-GitHub/39afeb64766eccce920fbaeac5f89f23 to your computer and use it in GitHub Desktop.
Save xgqfrms-GitHub/39afeb64766eccce920fbaeac5f89f23 to your computer and use it in GitHub Desktop.
es6-template-literals-nested & es6-template-literals-condition & es6-template-literals (advanced skill / in deepth)

es6-template-literals (advanced skill / in deepth)

es6-template-literals-nested & es6-template-literals-condition

orderGift += `
    <div class="order-gift cut-line">
        <div class="title">
            <span class="gf-lf">赠豆</span>
            <span class="gf-rt">${parseFloat(dadouoff).toFixed(2)}</span>
        </div>
        ${
            totalReduceMoney
             ? 
             `
             <div class="title">
                <span class="gf-lf">满减</span>
                <span class="gf-rt">${parseFloat(totalReduceMoney).toFixed(2)}</span>
            </div>
            `
            : 
            ``
        } 
        <div class="money">
            <span class="gf-lf">订单金额</span>
            <span class="gf-rt">${parseFloat(sum).toFixed(2)}</span>
        </div>
    </div>
`;
@xgqfrms-GitHub
Copy link
Author

Demo

// 赠豆 
orderGift += `
    <div class="order-gift cut-line">
        <div class="title">
            <span class="gf-lf">赠豆</span>
            <span class="gf-rt">${parseFloat(dadouoff).toFixed(2)}</span>
        </div>
        ${
            totalReduceMoney
             ? 
             `
             <div class="title">
                <span class="gf-lf">满减</span>
                <span class="gf-rt">${parseFloat(totalReduceMoney).toFixed(2)}</span>
            </div>
            `
            : 
            ``
        } 
        <div class="money">
            <span class="gf-lf">订单金额</span>
            <span class="gf-rt">${parseFloat(sum).toFixed(2)}</span>
        </div>
    </div>
`;


printFoot = `
    <div class="bd-extra">
        <div class="total">
            <span>商品总金额:</span>
            <span class="tt-money"> ${total}</span>
            <span>-赠豆:${dadouoff}</span>
            ${
                totalReduceMoney ? `<span>-满减:${totalReduceMoney} </span> : ''`
            }
            <span>-赠豆:${dadouoff}</span>
            <span class="gift"></span>
        </div>
        <div class="payed">
            <span>支付金额:${sum}</span>
        </div>
    </div>
`;

@xgqfrms-GitHub
Copy link
Author

格式:

OK

`
    ${
        var 
        ?
        ` ${var} `
        :
        ` ${var} `
    }
`

// OR

`
    ${
        ` ${var} `
        ?
        ` ${var} `
        :
        ` ${var} `
    }
`

error

${
    ${}
}

https://developer.mozilla.org/zh-CN/docs/Web/API/notification/Using_Web_Notifications

https://developer.mozilla.org/zh-CN/docs/Web/API/Notification/requestPermission

https://developer.mozilla.org/zh-CN/docs/Web/API/notification

OK demo

Notification.requestPermission()
    .then(function(permission){
        console.log(permission);
        console.log(typeof(permission));
        // denied / granted
        if(permission === 'granted'){
            console.log(`permission has been got!`)
        }else if(permission === 'denied'){
            console.log(`permission hasn't been got!`)
        }else{
            console.log(`permission Error!`)
        }
        // Nested Template String
        return ` 
            ${
                permission === `granted`
                ? 
                `${console.log("permission has been got!")}`
                :
                `${console.log("permission hasn't been got!")}`
            }
        `;
    }
);



Notification.requestPermission()
    .then(function(permission){
        console.log(permission);
        console.log(typeof(permission));
        // denied / granted
        if(permission === 'granted'){
            console.log(`permission has been got!`)
        }else if(permission === 'denied'){
            console.log(`permission hasn't been got!`)
        }else{
            console.log(`permission Error!`)
        }
        // Nested Template String
        return ` 
            ${
                `${permission === `granted`}`
                ? 
                `${console.log("permission has been got!")}`
                :
                `${console.log("permission hasn't been got!")}`
            }
        `;
    }
);

error demo

Notification.requestPermission()
    .then(function(permission){
        console.log(permission);
        console.log(typeof(permission));
        // denied
        // granted
        if(permission === 'granted'){
            console.log(`permission has been got!`)
        }else if(permission === 'denied'){
            console.log(`permission hasn't been got!`)
        }else{
            console.log(`permission Error!`)
        }
        return ` 
            ${permission}
            ${ === } 
            "granted"
            ${ ? }
            ${console.log("permission has been got!")}
            ${ : }
            ${console.log("permission hasn't been got!")}
        `;
    }
);


Notification.requestPermission()
    .then(function(permission){
        console.log(permission);
        console.log(typeof(permission));
        // denied
        // granted
        if(permission === 'granted'){
            console.log(`permission has been got!`)
        }else if(permission === 'denied'){
            console.log(`permission hasn't been got!`)
        }else{
            console.log(`permission Error!`)
        }
        return ` 
            ${
                ${permission === "granted"} 
                ${ ? }
                ${console.log("permission has been got!")}
                ${ : }
                ${console.log("permission hasn't been got!")}
            }
        `;
    }
);

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