Cocos Creator API

1.3.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 Any

:

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 Any

:

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