Cocos Creator API

1.0.0

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

Module js

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

Class

Methods

isFunction
(
  • obj
)
Boolean

Check the obj whether is function or not

name type description
obj

returns:

type: Boolean

isNumber
(
  • obj
)
Boolean

Check the obj whether is number or not

name type description
obj

returns:

type: Boolean

isString
(
  • obj
)
Boolean

Check the obj whether is string or not

name type description
obj

returns:

type: Boolean

isArray
(
  • obj
)
Boolean

Check the obj whether is array or not

name type description
obj

returns:

type: Boolean

isUndefined
(
  • obj
)
Boolean

Check the obj whether is undefined or not

name type description
obj

returns:

type: Boolean

isObject
(
  • obj
)
Boolean

Check the obj whether is object or not

name type description
obj

returns:

type: Boolean

addon
(
  • obj
  • sourceObj
)
Object

copy all properties not defined in obj from arguments[1...n]

name type description
obj Object

object to extend its properties

sourceObj Object

source object to copy properties from

returns:

type: Object

the result obj

mixin
(
  • obj
  • sourceObj
)
Object

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

name type description
obj Object
sourceObj Object

returns:

type: 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.

name type description
cls Function
base Function

the baseclass to inherit

returns:

type: Function

the result class

clear
(
  • obj
)

Removes all enumerable properties from object

name type description
obj Any

getPropertyDescriptor
(
  • obj
  • name
)
Object

Get property descriptor in object and all its ancestors

name type description
obj Object
name String

returns:

type: 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)

name type description
obj Object | Function

instance or constructor

returns:

type: String

_setClassId
(
  • classId
  • constructor
)
private

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

name type description
classId String
constructor Function

setClassName
(
  • className
  • constructor
)

Register the class by specified name manually

name type description
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.

name type description
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

name type description
classId String

returns:

type: Function

constructor

getClassByName
(
  • classname
)
Function

Get the registered class by name

name type description
classname String

returns:

type: Function

constructor

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

Get class id of the object

name type description
obj Object | Function

instance or constructor

allowTempId optional Boolean true

can return temp id in editor

returns:

type: String

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

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

name type description
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(...)

name type description
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(...)

name type description
obj Any
prop String
setter Function
enumerable optional Boolean false

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

Defines a polyfill field for obsoleted codes.

name type description
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.

name type description
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: %d, b: %b", a, b); cc.js.formatStr(a, b, c);

returns:

type: String