varmyClock={getSecondDeg:function(){vartime=newDate();varnow_seconds=time.getSeconds();var_deg=now_seconds*6return_deg;},getMinuteDeg:function(){vartime=newDate();varnow_minutes=time.getMinutes();varnow_seconds=time.getSeconds();var_deg=now_minutes*6+now_seconds/10return_deg;},getHourDeg:function(){vartime=newDate();varnow_hours=time.getHours();varnow_minutes=time.getMinutes();var_deg=now_hours%12*30+now_minutes/2;return_deg;},init:function(element){varclock_c=element;//時(shí)針varhour_p=document.createElement("div");hour_p.id="hour";//分針varminutes_p=document.createElement("div");minutes_p.id="minutes";//秒針varsecond_p=document.createElement("div");second_p.id="second";//刻度clock_c.appendChild(hour_p);clock_c.appendChild(minutes_p);clock_c.appendChild(second_p);myClock.refush(hour_p,minutes_p,second_p);setInterval(function(){myClock.refush(hour_p,minutes_p,second_p);},1000);},refush:function(hh,mm,ss){hh.style.transform='rotateZ('+myClock.getHourDeg()+'deg)';mm.style.transform='rotateZ('+myClock.getMinuteDeg()+'deg)';ss.style.transform='rotateZ('+(myClock.getSecondDeg()+1)+'deg)';setTimeout(function(){ss.style.transform='rotateZ('+myClock.getSecondDeg()+'deg)';},50);}}varclock=document.getElementById("clock")myClock.init(clock);我想將myClock.init(clock)改成clock.myClock.init()這樣的方式調(diào)用。還有只允許myClock中的Init()方法能被外部調(diào)用,其他方法為私有方法,改如何寫(xiě)。//我剛開(kāi)始這樣寫(xiě)的會(huì)報(bào)錯(cuò)varclock=function(){init=function(element){}//....returninit;}
如何編寫(xiě)javascript組件
動(dòng)漫人物
2019-04-21 20:39:50