zoukankan      html  css  js  c++  java
  • template-string

    var s1 = `string text`;
    console.log(s1);
    console.log(typeof(s1));
    
    var s2 =`text line1
        text line2`;
    
    console.log(s2);
    
    // true
    console.log('\`' === '`');
    
    
    var a = 1,
        b = 2;
    console.log(`sum is ${a + b} 
     sub is $(b - a)`);
    
    
    // template strings with tag
    var a = 5,
    	b = 10;
    function tag(strings, ...values)
    {
        // console.log(strings);
        // console.log(strings.length);
        console.log(strings[0]);
        console.log(strings[1]);
        console.log(strings[2]);
        console.log(values[0]);
        console.log(values[1]);
    
        return "something";
    }
    
    //foo === 'something'
    var foo = tag`hello ${a + b} world ${a * b}`;
    
    
    function template(strings, ...values)
    {
    	console.log(strings);
    	console.log(values);
    }
    template`${0}${1}${0}`;
    

      

  • 相关阅读:
    preprocess
    数组
    共用体
    动态内存管理函数
    C链表
    文件的定位与出错检查
    字符串读写函数
    C文件操作
    位运算
    爱好-超级IP:超级IP
  • 原文地址:https://www.cnblogs.com/ax-null/p/6803938.html
Copyright © 2011-2022 走看看