From 4a7d2e93e4641e2ce0e1181347c8972bb7413b96 Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Tue, 11 Sep 2018 16:00:57 +0800 Subject: [PATCH] refine toString API intro (#3225) --- cocos/assets/CCAsset.js | 7 +++++-- cocos/assets/CCTextAsset.js | 8 ++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/cocos/assets/CCAsset.js b/cocos/assets/CCAsset.js index c661073789..84b5213c74 100644 --- a/cocos/assets/CCAsset.js +++ b/cocos/assets/CCAsset.js @@ -163,12 +163,15 @@ export default class Asset extends RawAsset { static preventPreloadNativeObject = false; /** - * Returns the asset's url. + * Returns the string representation of the object. * * The `Asset` object overrides the `toString()` method of the `Object` object. - * For `Asset` objects, the toString() method returns a string representation of the object. * JavaScript calls the toString() method automatically when an asset is to be represented as a text value or when a texture is referred to in a string concatenation. * + * For assets of the native type, it will return `this.nativeUrl`. + * Otherwise, an empty string is returned. + * This method may be overwritten by subclasses. + * * @method toString * @return {String} */ diff --git a/cocos/assets/CCTextAsset.js b/cocos/assets/CCTextAsset.js index 3688232b01..defdb3f665 100644 --- a/cocos/assets/CCTextAsset.js +++ b/cocos/assets/CCTextAsset.js @@ -44,6 +44,14 @@ export default class TextAsset extends Asset { @property() text = ""; + /** + * Returns the text content of the asset. + * + * JavaScript calls the toString() method automatically when an asset is to be represented as a text value or when a texture is referred to in a string concatenation. + * + * @method toString + * @return {String} + */ toString () { return this.text; }