0%

Chrome console & Debugging

Chrome console .. & debuging in chrome ..

  • logging with console.log(...)
  • breakpoints & debugger cmd, execution tracking …

‘use strict’

To enable ES5

  • off by default — always put 'use script' on top of script/fn-body
    • auto enable for class & module
    • no way to cancel once enter strict mode
  • non-strict: assignment to non-existing var (without declear) ==> create a new global var (for compatibility) ..
Read more »

async actions: init now but finish later (code below it won’t wait) ..

Callback

loadScript('xxx.js', (error, script) => { .. }) (“error-1st” cb style) ..: cb hell / pyramid of doom
Fn Call Scheduling: setTimeout/setInterval(..) .. (enqueue in macrotask ..)

1
2
let timerId = setTimeout/setInterval(fn, delay=0, ...args); // keep fn-ref in scheduler (not GC) 
clearTimeout/clearInterval(timerId); // "timerId keep same" af clear (not null)
  • setTimeout(): set this=window ..
  • setInterval(): fn-exe-time > delay?
  • nested setTimeout vs setInterval ..
  • tasks: Output every second
Read more »

JS intro

  • init to make webpages alive .., run on platforms with JS engine (in browser aka “JS VM”, e.g. “V8” in Chrome & Opera) ..
    • browser env: window (root obj) => JS / DOM / BOM ..
    • BOM: navigator obj, location.href, model win fn: alert(), prompt(), confirm() ..
  • JS in HTML: <script>..</script> & <script src=..></script> ..
    • type="text/javascript" language="javascript" attr no need anymore ..
    • inline content ignored if src set ..
    • browser cache external script for re-use ..
  • in-browser JS restrictions
Read more »