Programming Pearls

Programming Pearls

二月 17, 2018

Learning programming pearls

call/apply的first parameter is null, then this point to window

1
2
3
4
5
6
7
8
9
10
var aStr = 'strInWindow'
var bStr = 'strInWindow'
var str ='done'
var object = {aStr:'strInObj',bStr:'strInObj'}
function hello(str) {
console.log(`aStr=${this.aStr}, bStr=${this.bStr} ${str}`)
}

hello.call(null, str) // => aStr=strInWindow, bStr=strInWindow done
hello.call(object, str) // => aStr=strInObj, bStr=strInObj done

不超过32位整数表示的意思, check here