外文文献与翻译

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

JavaScriptWhenIwasayoungjourneymanprogrammer,IwouldlearnabouteveryfeatureofthelanguagesIwasusing,andIwouldattempttouseallofthosefeatureswhenIwrote.Isupposeitwasawayofshowingoff,andIsupposeitworkedbecauseIwastheguyyouwenttoifyouwantedtoknowhowtouseaparticularfeature.EventuallyIfiguredoutthatsomeofthosefeaturesweremoretroublethantheywereworth.Someofthemwerepoorlyspecified,andsoweremorelikelytocauseportabilityproblems.Someresultedincodethatwasdifficulttoreadormodify.Someinducedmetowriteinamannerthatwastootrickyanderror-prone.Andsomeofthosefeaturesweredesignerrors.Sometimeslanguagedesignersmakemistakes.Mostprogramminglanguagescontaingoodpartsandbadparts.IdiscoveredthatIcouldbeabetterprogrammerbyusingonlythegoodpartsandavoidingthebadparts.Afterall,howcanyoubuildsomethinggoodoutofbadparts?Itisrarelypossibleforstandardscommitteestoremoveimperfectionsfromalanguagebecausedoingsowouldcausethebreakageofallofthebadprogramsthatdependonthosebadparts.Theyareusuallypowerlesstodoanythingexceptheapmorefeaturesontopoftheexistingpileofimperfections.Andthenewfeaturesdonotalwaysinteractharmoniously,thusproducingmorebadparts.Butyouhavethepowertodefineyourownsubset.Youcanwritebetterprogramsbyrelyingexclusivelyonthegoodparts.JavaScriptisalanguagewithmorethanitsshareofbadparts.Itwentfromnon-existencetoglobaladoptioninanalarminglyshortperiodoftime.Itneverhadanintervalinthelabwhenitcouldbetriedoutandpolished.ItwentstraightintoNetscapeNavigator2justasitwas,anditwasveryrough.WhenJava™appletsfailed,JavaScriptbecametheLanguageoftheWebbydefault.JavaScript'spopularityisalmostcompletelyindependentofitsqualitiesasaprogramminglanguage.Fortunately,JavaScripthassomeextraordinarilygoodparts.InJavaScript,thereisabeautiful,elegant,highlyexpressivelanguagethatisburiedunderasteamingpileofgoodintentionsandblunders.ThebestnatureofJavaScriptissoeffectivelyhiddenthatformanyyearstheprevailingopinionofJavaScriptwasthatitwasanunsightly,incompetenttoy.MyintentionhereistoexposethegoodnessinJavaScript,anoutstanding,dynamicprogramminglanguage.JavaScriptisablockofmarble,andIchipawaythefeaturesthatarenotbeautifuluntilthelanguage'struenaturerevealsitself.IbelievethattheelegantsubsetIcarvedoutisvastlysuperiortothelanguageasawhole,beingmorereliable,readable,andmaintainable.Thisbookwillnotattempttofullydescribethelanguage.Instead,itwillfocusonthegoodpartswithoccasionalwarningstoavoidthebad.Thesubsetthatwillbedescribedherecanbeusedtoconstructreliable,readableprogramssmallandlarge.Byfocusingonjustthegoodparts,wecanreducelearningtime,increaserobustness,andsavesometrees.Perhapsthegreatestbenefitofstudyingthegoodpartsisthatyoucanavoidtheneedtounlearnthebadparts.Unlearningbadpatternsisverydifficult.Itisapainfultaskthatmostofusfacewithextremereluctance.Sometimeslanguagesaresubsettedtomakethemworkbetterforstudents.Butinthiscase,IamsubsettingJavaScripttomakeitworkbetterforprofessionals.WhyJavaScript?JavaScriptisanimportantlanguagebecauseitisthelanguageofthewebbrowser.Itsassociationwiththebrowsermakesitoneofthemostpopularprogramminglanguagesintheworld.Atthesametime,itisoneofthemostdespisedprogramminglanguagesintheworld.TheAPIofthebrowser,theDocumentObjectModel(DOM)isquiteawful,andJavaScriptisunfairlyblamed.TheDOMwouldbepainfultoworkwithinanylanguage.TheDOMispoorlyspecifiedandinconsistentlyimplemented.ThisbooktouchesonlyverylightlyontheDOM.IthinkwritingaGoodPartsbookabouttheDOMwouldbeextremelychallenging.JavaScriptismostdespisedbecauseitisn'tSOMEOTHERLANGUAGE.IfyouaregoodinSOMEOTHERLANGUAGEandyouhavetoprograminanenvironmentthatonlysupportsJavaScript,thenyouareforcedtouseJavaScript,andthatisannoying.Mostpeopleinthatsituationdon'tevenbothertolearnJavaScriptfirst,andthentheyaresurprisedwhenJavaScriptturnsouttohavesignificantdifferencesfromtheSOMEOTHERLANGUAGEtheywouldratherbeusing,andthatthosedifferencesmatter.TheamazingthingaboutJavaScriptisthatitispossibletogetworkdonewithitwithoutknowingmuchaboutthelanguage,orevenknowingmuchaboutprogramming.Itisalanguagewithenormousexpressivepower.Itisevenbetterwhenyouknowwhatyou'redoing.Programmingisdifficultbusiness.Itshouldneverbeundertakeninignorance.AnalyzingJavaScriptJavaScriptisbuiltonsomeverygoodideasandafewverybadones.Theverygoodideasincludefunctions,loosetyping,dynamicobjects,andanexpressiveobjectliteralnotation.Thebadideasincludeaprogrammingmodelbasedonglobalvariables.JavaScript'sfunctionsarefirstclassobjectswith(mostly)lexicalscoping.JavaScriptisthefirstlambdalanguagetogomainstream.Deepdown,JavaScripthasmoreincommonwithLispandSchemethanwithJava.ItisLispinC'sclothing.ThismakesJavaScriptaremarkablypowerfullanguage.Thefashioninmostprogramminglanguagestodaydemandsstrongtyping.Thetheoryisthatstrongtypingallowsacompilertodetectalargeclassoferrorsatcompiletime.Thesoonerwecandetectandrepairerrors,thelesstheycostus.JavaScriptisalooselytypedlanguage,soJavaScriptcompilersareunabletodetecttypeerrors.ThiscanbealarmingtopeoplewhoarecomingtoJavaScriptfromstronglytypedlanguages.Butitturnsoutthatstrongtypingdoesnoteliminatetheneedforcarefultesting.A

1 / 9
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功