您好,欢迎访问三七文档
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
三七文档所有资源均是用户自行上传分享,仅供网友学习交流,未经上传用户书面授权,请勿作他用。
本文标题:外文文献与翻译
链接地址:https://www.777doc.com/doc-4304670 .html