refine cc.instantiate API doc

This commit is contained in:
Jare Guo
2017-05-17 14:49:05 +08:00
parent 4393080acf
commit da567994c3
2 changed files with 36 additions and 24 deletions
+32 -24
View File
@@ -30,16 +30,10 @@ var Attr = require('./attribute');
var _isDomNode = require('./utils').isDomNode;
/**
* !#en Clones the object original and returns the clone.
* !#en Clones the object `original` and returns the clone, or instantiate a node from the Prefab.
* !#zh 克隆指定的任意类型的对象,或者从 Prefab 实例化出新节点。
*
* See [Clone exists Entity](/en/scripting/create-destroy-entities/#instantiate)
*
* !#zh 复制给定的对象
*
* 详细用法可参考[复制已有Entity](/zh/scripting/create-destroy-entities/#instantiate)
*
* Instantiate 时,function 和 dom 等非可序列化对象会直接保留原有引用,Asset 会直接进行浅拷贝,可序列化类型会进行深拷贝。
* <del>对于 Entity / Component 等 Scene Object,如果对方也会被一起 Instantiate,则重定向到新的引用,否则保留为原来的引用。</del>
* (Instantiate 时,function 和 dom 等非可序列化对象会直接保留原有引用,Asset 会直接进行浅拷贝,可序列化类型会进行深拷贝。)
*
* @method instantiate
* @param {Prefab|Node|Object} original - An existing object that you want to make a copy of.
@@ -47,25 +41,39 @@ var _isDomNode = require('./utils').isDomNode;
* @typescript
* instantiate(original: Prefab): Node
* instantiate<T>(original: T): T
* @example
* // instantiate node from prefab
* var scene = cc.director.getScene();
* var node = cc.instantiate(prefabAsset);
* node.parent = scene;
* // clone node
* var scene = cc.director.getScene();
* var node = cc.instantiate(targetNode);
* node.parent = scene;
*/
function instantiate (original) {
if (typeof original !== 'object' || Array.isArray(original)) {
if (CC_DEV) {
cc.errorID(6900);
function instantiate (original, internal_force) {
if (!internal_force) {
if (typeof original !== 'object' || Array.isArray(original)) {
if (CC_DEV) {
cc.errorID(6900);
}
return null;
}
return null;
}
if (!original) {
if (CC_DEV) {
cc.errorID(6901);
if (!original) {
if (CC_DEV) {
cc.errorID(6901);
}
return null;
}
return null;
}
if (!cc.isValid(original)) {
if (CC_DEV) {
cc.errorID(6902);
if (!cc.isValid(original)) {
if (CC_DEV) {
cc.errorID(6902);
}
return null;
}
if (CC_DEV && original instanceof cc.Component) {
cc.warn('Should not instantiate a single cc.Component directly, you must instantiate the entire node.');
}
return null;
}
var clone;
+4
View File
@@ -451,6 +451,10 @@ cc.SpriteFrame = cc.Class(/** @lends cc.SpriteFrame# */{
}
},
// _instantiate () {
// var clone = new cc.SpriteFrame();
// },
// SERIALIZATION
_serialize: CC_EDITOR && function (exporting) {