Cocos Creator API

1.2.0

Cocos Creator is a highly customizable game development tool that utilizes the power of cocos2d-x.

模块 js

This module provides some JavaScript utilities. All members can be accessed with cc.js

类型

方法

isNumber
(
  • obj
)
Boolean

Check the obj whether is number or not If a number is created by using 'new Number(10086)', the typeof it will be "object"... Then you can use this function if you care about this case.

名称 类型 描述
obj

返回:

类型: Boolean

isString
(
  • obj
)
Boolean

Check the obj whether is string or not. If a string is created by using 'new String("blabla")', the typeof it will be "object"... Then you can use this function if you care about this case.

名称 类型 描述
obj

返回:

类型: Boolean

addon
(
  • obj
  • sourceObj
)
Object deprecated

This method is deprecated, use cc.js.mixin please.
Copy all properties not defined in obj from arguments[1...n]

名称 类型 描述
obj Object

object to extend its properties

sourceObj Object

source object to copy properties from

返回:

类型: Object

the result obj

mixin
(
  • obj
  • sourceObj
)
Object

copy all properties from arguments[1...n] to obj

名称 类型 描述
obj Object
sourceObj Object

返回:

类型: Object

the result obj

extend
(
  • cls
  • base
)
Function

Derive the class from the supplied base class. Both classes are just native javascript constructors, not created by cc.Class, so usually you will want to inherit using cc.Class instead.

名称 类型 描述
cls Function
base Function

the baseclass to inherit

返回:

类型: Function

the result class

clear
(
  • obj
)

Removes all enumerable properties from object

名称 类型 描述
obj Any

getPropertyDescriptor
(
  • obj
  • name
)
Object

Get property descriptor in object and all its ancestors

名称 类型 描述
obj Object
name String

返回:

类型: Object

getClassName
(
  • obj
)
String

Get class name of the object, if object is just a {} (and which class named 'Object'), it will return null. (modified from the code from this stackoverflow post)

名称 类型 描述
obj Object | Function

instance or constructor

返回:

类型: String

_setClassId
(
  • classId
  • constructor
)
private

Register the class by specified id, if its classname is not defined, the class name will also be set.

名称 类型 描述
classId String
constructor Function

setClassName
(
  • className
  • constructor
)

Register the class by specified name manually

名称 类型 描述
className String
constructor Function

unregisterClass
(
  • constructor
)

Unregister a class from fireball.

If you dont need a registered class anymore, you should unregister the class so that Fireball will not keep its reference anymore. Please note that its still your responsibility to free other references to the class.

名称 类型 描述
constructor Function

the class you will want to unregister, any number of classes can be added

_getClassById
(
  • classId
)
Function private

Get the registered class by id

名称 类型 描述
classId String

返回:

类型: Function

constructor

getClassByName
(
  • classname
)
Function

Get the registered class by name

名称 类型 描述
classname String

返回:

类型: Function

constructor

_getClassId
(
  • obj
  • [allowTempId =true]
)
String private

Get class id of the object

名称 类型 描述
obj Object | Function

instance or constructor

allowTempId optional Boolean true

can return temp id in editor

返回:

类型: String

getset
(
  • obj
  • prop
  • getter
  • setter
  • [enumerable =false]
)

Define get set accessor, just help to call Object.defineProperty(...)

名称 类型 描述
obj Any
prop String
getter Function
setter Function
enumerable optional Boolean false

get
(
  • obj
  • prop
  • getter
  • [enumerable =false]
)

Define get accessor, just help to call Object.defineProperty(...)

名称 类型 描述
obj Any
prop String
getter Function
enumerable optional Boolean false

set
(
  • obj
  • prop
  • setter
  • [enumerable =false]
)

Define set accessor, just help to call Object.defineProperty(...)

名称 类型 描述
obj Any
prop String
setter Function
enumerable optional Boolean false

obsolete
(
  • obj
  • obsoleted
  • newPropName
  • [writable =false]
)

Defines a polyfill field for obsoleted codes.

名称 类型 描述
obj Any

YourObject or YourClass.prototype

obsoleted String

"OldParam" or "YourClass.OldParam"

newPropName String

"NewParam"

writable optional Boolean false

obsoletes
(
  • obj
  • objName
  • props
  • [writable =false]
)

Defines all polyfill fields for obsoleted codes corresponding to the enumerable properties of props.

名称 类型 描述
obj Any

YourObject or YourClass.prototype

objName Any

"YourObject" or "YourClass"

props Object
writable optional Boolean false

formatStr ( ) String

A string tool to construct a string with format string. for example: cc.js.formatStr("a: %s, b: %s", a, b); cc.js.formatStr(a, b, c);

返回:

类型: String