《cocos2d-js教学》javascript_quicksta_第1页
《cocos2d-js教学》javascript_quicksta_第2页
《cocos2d-js教学》javascript_quicksta_第3页
《cocos2d-js教学》javascript_quicksta_第4页
《cocos2d-js教学》javascript_quicksta_第5页
已阅读5页,还剩43页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、JAVASCRIPT QUICKSTARTJIANYUN BAO,SENIOR TECHNICAL EVANGELIST, CHUKONGTHE TECHNOLOGY OF MOBILE GAME DEVELOPMENTWhat is JavaScript ?WHAT IS JAVASCRIPT http:/ IS JAVASCRIPT WHAT IS JAVASCRIPT a cross-platform, object-oriented scripting language01inside a host environment (eg. a web browser)03variable d

2、ata types are not declared (dynamic typing)02Why is JavaScript?WHY IS JAVASCRIPT Functional Programming01Simpler code, rapider development 02Close to natural language, easy to understand03Code management easier04Concurrent programming easier 05Code hot updatehttphttpWHY IS JAVASCRIPT Fullstack javas

3、cript framework for web application developmentWHY IS JAVASCRIPT httpJavaScript basic knowledgeDATA TYPE AND VARIABLESDEFINITIONExplicit use var for assignmentImplicit direct assignmentDATA TYPE AND VARIABLESTYPE CONVERSION subtraction (string number) + addition string joint / numbertoString() boole

4、an / number stringDATA TYPE AND VARIABLESTYPE CONVERSIONparseInt() string integerparseFloat() string float non number string NaNDATA TYPE AND VARIABLESVARIABLEScoverage Local override GlobalBASIC DATA TYPEnumber integer / floatboolean true / falsestring must use or “”undefined created but not initia

5、lized variablesnull variables have not dataCOMPOUND TYPESObject object-orientedArray or OBJECTS or new Array()Functiondefinition function functionName(param, ) call functionName(param, );typeof check data typeCOMPOUND TYPESOPERATOR!= / = check value!= / = check value and data type5 = “5” is true (Au

6、tomatic type conversion)null = undefined is true null = undefined is false , (comma) allow Expression place togerther, finally return the rightest value finally a s value is 13OPERATORinstanceof check the variable whether a instance of some data type refer to typeofOPERATORblocks need but dont need

7、; finallySTATEMENTtry catch exception catchingSTATEMENTwith avoid writing object repeatlySTATEMENTIf else if else two branchesFLOW CONTROLBRANCHswitch multi-brancheswhile / do while loop by expressionFLOW CONTROLLOOPfor loop in sectionFLOW CONTROLLOOPendless loop for in kind of foreach loop FLOW CON

8、TROLLOOPtraverse all elements in the array traverse all attributes of JavaScript object continue stop current loop FLOW CONTROLLOOPbreak stop whole loop stop external loop (name: looper) FUNCTIONDEFINITIONNotice do not need declare return type do not need declare parameter type name function FUNCTIO

9、NDEFINITIONanonymous function FUNCTIONDEFINITIONFunction class anonymous function FUNCTIONDEFINITIONthe number of parameters in constructor is unlimited allow a series of string parameters, and the last one is the executive of the function, the statements are separated by “;” (semicolon)Function cla

10、ss anonymous function FUNCTIONDEFINITIONwhen define a function in JavaScript FUNCTIONFUNCTION, OBJECT, METHOD AND CLASSfunction directly call like Java method object also create a object (Function) method append some object as method class also get a Class, has the same name of the functionFUNCTIONC

11、ALLdirect call usually get the last return value non return, get null use new call return this JavaScript objectFUNCTIONTHISthis instance attribute FUNCTIONATTRIBUTElocal variable use var or not declare variable in the functioninstance attribute this prefixclass attribute function name prefixFUNCTIO

12、NCALL METHODdirect call method xxx.foo(para);use call() dynamically call with all parametersuse apply() dynamically call with arguments (array)PARAMETERTYPEempty parameter input as undefined“Duck Type” check type, attribute, method first USE OBJECTOBJECT-ORIENTEDnotice the definition of function doe

13、s not support inheritance syntax inheritance mechanism is not perfectUSE OBJECTOBJECT AND LINKED DATAnotice the object of JavaScript is linked data like Map in Java, “key-value” USE OBJECTINHERITANCE AND PROTOTYPEnotice use “prototype” as pseudo inheritancemechanismevery class has prototype attributewhen extend function and attribute to prototype, as extend the originalclassCocos2d-JS v2.x use thisCREATE OBJECTuse new create CREATE OBJECTuse object create create null object, add function and attribute CREATE OBJECTuse JSON synta

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论