function test(txt){ this.key=['red','green','blue'] this.newArray=txt //this.key.push(txt)}
function test1(){
test.apply(this,['yellow','orgen'])
}var fun=new test1()fun.newArray=====>"yellow"傳入的是一個數組test里通過txt拿到的卻是個字符串"yellow"但是將apply換成callfunction test(txt){ this.key=['red','green','blue'] this.newArray=txt //this.key.push(txt)}
function test1(){
test.call(this,['yellow','orgen'])
}var fun=new test1()fun.newArray=====>["yellow", "orgen"]得到的卻是["yellow", "orgen"]如果放開this.key.push(txt)在構造函數內部拼接數組最后得到的是["red", "green", "blue", "yellow"](apply換成call也一樣)但是將push放到函數外在實例引用時拼接便能拿到兩個數組拼接到一起的情況function test(txt){ this.key=['red','green','blue'] this.newArray=txt //this.key.push(txt)}
function test1(){
test.call(this,['yellow','orgen'])
}var fun=new test1()fun.key.concat(fun.newArray)=====>["red", "green", "blue", "yellow", "orgen"]目的在構造函數內部完成數組正確拼接
apply傳入的數組怎么處理,凌亂了。。。
慕虎7371278
2018-10-18 14:11:33