js Module

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

Classes

Index

Methods
  • isNumber 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.
  • isString 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.
  • addon This method is deprecated, use cc.js.mixin please.
    Copy all properties not defined in obj from arguments[1...n]
  • mixin copy all properties from arguments[1...n] to obj
  • extend 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.
  • getSuper Get super class
  • clear Removes all enumerable properties from object
  • getPropertyDescriptor Get property descriptor in object and all its ancestors
  • value Define value, just help to call Object.defineProperty.
    The configurable will be true.
  • getset Define get set accessor, just help to call Object.defineProperty(...)
  • get Define get accessor, just help to call Object.defineProperty(...)
  • set Define set accessor, just help to call Object.defineProperty(...)
  • getClassName Get class name of the object, if object is just a {} (and which class named 'Object'), it will return "". (modified from the code from this stackoverflow post)
  • _setClassId Register the class by specified id, if its classname is not defined, the class name will also be set.
  • setClassName Register the class by specified name manually
  • unregisterClass 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.

  • _getClassById Get the registered class by id
  • getClassByName Get the registered class by name
  • _getClassId Get class id of the object
  • obsolete Defines a polyfill field for obsoleted codes.
  • obsoletes Defines all polyfill fields for obsoleted codes corresponding to the enumerable properties of props.
  • formatStr A string tool to construct a string with format string.
  • createMap A simple wrapper of Object.create(null) which ensures the return object have no prototype (and thus no inherited members). So we can skip hasOwnProperty calls on property lookups. It is a worthwhile optimization than the {} literal when hasOwnProperty calls are necessary.

Details

Methods

isNumber

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.

meta description
Returns Boolean
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/platform/js.js:57
Parameters
  • obj Any
isString

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.

meta description
Returns Boolean
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/platform/js.js:69
Parameters
  • obj Any
addon

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

meta description
Returns Object
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/platform/js.js:81
Parameters
  • obj Object object to extend its properties
  • sourceObj Object source object to copy properties from
mixin

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

meta description
Returns Object
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/platform/js.js:110
Parameters
extend

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.

meta description
Returns Function
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/platform/js.js:135
Parameters
getSuper

Get super class

meta description
Returns Function
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/platform/js.js:169
Parameters
  • ctor Function the constructor of subclass
clear

Removes all enumerable properties from object

meta description
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/platform/js.js:188
Parameters
  • obj Any
getPropertyDescriptor

Get property descriptor in object and all its ancestors

meta description
Returns Object
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/platform/js.js:200
Parameters
value

Define value, just help to call Object.defineProperty.
The configurable will be true.

meta description
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/platform/js.js:218
Parameters
getset

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

meta description
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/platform/js.js:242
Parameters
get

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

meta description
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/platform/js.js:270
Parameters
set

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

meta description
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/platform/js.js:293
Parameters
getClassName

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

meta description
Returns String
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/platform/js.js:310
Parameters
_setClassId

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

meta description
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/platform/js.js:388
Parameters
setClassName

Register the class by specified name manually

meta description
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/platform/js.js:399
Parameters
unregisterClass

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.

meta description
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/platform/js.js:416
Parameters
  • constructor Function the class you will want to unregister, any number of classes can be added
_getClassById

Get the registered class by id

meta description
Returns Function
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/platform/js.js:439
Parameters
getClassByName

Get the registered class by name

meta description
Returns Function
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/platform/js.js:450
Parameters
_getClassId

Get class id of the object

meta description
Returns String
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/platform/js.js:460
Parameters
obsolete

Defines a polyfill field for obsoleted codes.

meta description
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/platform/js.js:527
Parameters
  • obj Any YourObject or YourClass.prototype
  • obsoleted String "OldParam" or "YourClass.OldParam"
  • newPropName String "NewParam"
  • writable Boolean
obsoletes

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

meta description
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/platform/js.js:559
Parameters
  • obj Any YourObject or YourClass.prototype
  • objName Any "YourObject" or "YourClass"
  • props Object
  • writable Boolean
formatStr

A string tool to construct a string with format string.

meta description
Returns String
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/platform/js.js:577
Parameters
  • msg String | Any A JavaScript string containing zero or more substitution strings (%s).
  • subst Any JavaScript objects with which to replace substitution strings within msg. This gives you additional control over the format of the output.
Examples
cc.js.formatStr("a: %s, b: %s", a, b);
cc.js.formatStr(a, b, c);
createMap

A simple wrapper of Object.create(null) which ensures the return object have no prototype (and thus no inherited members). So we can skip hasOwnProperty calls on property lookups. It is a worthwhile optimization than the {} literal when hasOwnProperty calls are necessary.

meta description
Returns Object
Defined in https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/platform/js.js:626
Parameters
  • forceDictMode Boolean Apply the delete operator to newly created map object. This causes V8 to put the object in "dictionary mode" and disables creation of hidden classes which are very expensive for objects that are constantly changing shape.

results matching ""

    No results matching ""