第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

為什么我這樣寫,會(huì)出現(xiàn)原型上沒有定義的這個(gè)問題

http://img1.sycdn.imooc.com//5710bfcc00017d9508360657.jpg



按照老師的方法寫的,為什么我這個(gè)會(huì)出現(xiàn)這樣的問題;

var?ball1?=?document.querySelector('.ball1');
var?ball1?=?document.querySelector('.ball2');
var?ball1?=?document.querySelector('.ball3');
var?Promise?=?window.Promise;
//
//
//????function?animation(ball,?distance,cb)?{
//??????????setTimeout(function()?{
//??????????????var?marginleft?=?parseInt(ball.style.marginLeft,10);
//??????????????if?(marginleft?===?distance)?{
//??????????????????cb&cb()
//??????????????}?else?{
//??????????????????if?(marginleft?>?distance)?{
//??????????????????????marginleft--;
//??????????????????}?else?{
//??????????????????????marginleft++;
//??????????????????}
//??????????????????ball.style.marginleft?=?marginleft;
//??????????????????animation(ball,?distance,cb);
//??????????????}
//
//??????????},?13);
//??????};
//??????animation();
//??????
//??????animation(ball1,200,function(){
//??????????animation(ball2,300,function(){
//??????????????animation(ball3,400,function(){
//??????????????????animation(ball3,250,function(){
//??????????????????????animation(ball2,250,function(){
//??????????????????????????animation(ball1,250)
//??????????????????????})
//??????????????????})
//??????????????})
//??????????});
//??????});
//??????
????????
????????
????????


function?promiseAnimation(ball,?distance)?{
????return?new?Promise(function(resole,?reject)?{
????????function?animation(ball)?{
????????????setTimeout(function()?{
????????????????var?marginLeft?=?parseInt(ball.style.marginLeft,10);
????????????????if?(marginLeft?===?distance)?{
????????????????????resole();
????????????????}?else?{
????????????????????if?(marginLeft?>?distance)?{
????????????????????????marginLeft--;
????????????????????}?else?{
????????????????????????marginLeft++;
????????????????????}
????????????????????ball.style.marginLeft?=?marginLeft;
????????????????????animation();
????????????????}

????????????},?13);
????????};
????????animation();
????});
};

promiseAnimation(ball1,?100)
????.then(function()?{
????????return?promiseAnimation(ball2,?200)
????})
????.then(function()?{
????????return?promiseAnimation(ball3,?300)
????})
????.then(function()?{
????????return?promiseAnimation(ball3,?150)
????})
????.then(function()?{
????????return?promiseAnimation(ball2,?150)
????})
????.then(function()?{
????????return?promiseAnimation(ball1,?150)
????})


正在回答

1 回答

Promise中的animation()函數(shù)在定義的時(shí)候加了ball這個(gè)參數(shù)。在調(diào)用的時(shí)候卻沒有傳參,函數(shù)內(nèi)的ball就是undefined。定義animation的時(shí)候去掉參數(shù)。讓函數(shù)內(nèi)animation的ball取promiseAnimation()中的參數(shù)ball。

0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

蛋疼少年的和諧青春 提問者

按照您說的修改后,將我遇到的錯(cuò)誤修復(fù)成功了,感謝。 可是后來出現(xiàn)了另外一個(gè)問題,運(yùn)行node的時(shí)候 報(bào)錯(cuò) var ball1 = document.querySelector('.ball1'); ^ ReferenceError: document is not defined 這個(gè)讓我很困惑。如果您還有時(shí)間幫我解答一下這個(gè)是什么原因。萬分感謝。
2016-04-17 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消
進(jìn)擊Node.js基礎(chǔ)(二)
  • 參與學(xué)習(xí)       76719    人
  • 解答問題       242    個(gè)

本教程帶你攻破 Nodejs,讓 JavaScript流暢運(yùn)行在服務(wù)器端

進(jìn)入課程

為什么我這樣寫,會(huì)出現(xiàn)原型上沒有定義的這個(gè)問題

我要回答 關(guān)注問題
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)