美文网首页
不一样的Console~~~

不一样的Console~~~

作者: zz77zz | 来源:发表于2018-03-29 16:19 被阅读11次

    console 不只能用来调试 还能做很多有意思的things

    • 直接上代码
    const dogs = [{ name: 'Snickers', age: 2 }, { name: 'hugo', age: 8 }];
    
        function makeGreen() {
          const p = document.querySelector('p');
          p.style.color = '#BADA55';
          p.style.fontSize = '50px';
        }
    
        // Regular
        console.log('hello')
        // Interpolated
        console.log(console.log('Hello I am a %s string!', '💩'))
        // Styled
        console.log('%c I am some great text', 'font-size:50px; background:red; text-shadow: 10px 10px 0 blue')
        // warning!
        console.warn('OH NONONO!!!')
        // Error :|
        console.error('SHIT!!')
        // Info
        console.info('今天,你写代码了么?')
        // Testing  
        const p = document.querySelector('p');
    
        console.assert(p.classList.contains('ouch'),'Thats wrong');
        // clearing
        // console.clear()
    
        // Viewing DOM Elements
        console.log(p)
        console.dir(p)
        // Grouping together
        dogs.forEach(dog =>{
            console.groupCollapsed(`${dog.name}`);
            console.log(`This is ${dog.name}`);
            console.log(`${dog.name} is ${dog.age} years old`);
            console.log(`${dog.name} is ${dog.age*7} dog years old`);
            console.groupEnd(`${dog.name}`)
        })
    
        // counting
        console.count('Wes');
        console.count('Wes');
        console.count('Steve');
        console.count('Steve');
        console.count('Wes');
        console.count('Steve');
        console.count('Wes');
        console.count('Steve');
        console.count('Steve');
        console.count('Steve');
        console.count('Steve');
        console.count('Steve');
        // timing
        console.time('fetching data');
        fetch('https://api.github.com/users/wesbos')
          .then(data => data.json())
          .then(data => {
            console.timeEnd('fetching data');
            console.log(data);
          });
    
        console.table(dogs);
    

    相关文章

      网友评论

          本文标题:不一样的Console~~~

          本文链接:https://www.haomeiwen.com/subject/renmcftx.html