Trevor Parscal has uploaded a new change for review.
https://gerrit.wikimedia.org/r/70758
Change subject: ve.isInstanceOfAny utility function
......................................................................
ve.isInstanceOfAny utility function
Convenient way to check if an object is an instance of one or more classes.
This should probably be moved to oo.js.
Change-Id: I2be55d9501cf62fde006281f1cf4813095b39b41
---
M modules/ve/ve.js
1 file changed, 19 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor
refs/changes/58/70758/1
diff --git a/modules/ve/ve.js b/modules/ve/ve.js
index 1c4bf80..efb9c40 100644
--- a/modules/ve/ve.js
+++ b/modules/ve/ve.js
@@ -40,6 +40,25 @@
ve.inheritClass = oo.inheritClass;
/**
+ * Checks if an object is an instance of one or more classes.
+ *
+ * @method
+ * @param {Object} subject Object to check
+ * @param {Function[]} classes Classes to compare with
+ * @return {boolean} Object inherits from one or more of the classes
+ */
+ ve.isInstanceOfAny = function ( subject, classes ) {
+ var i = classes.length;
+
+ while ( classes[--i] ) {
+ if ( subject instanceof classes[i] ) {
+ return true;
+ }
+ }
+ return false;
+ };
+
+ /**
* @method
* @inheritdoc OO#mixinClass
*/
--
To view, visit https://gerrit.wikimedia.org/r/70758
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I2be55d9501cf62fde006281f1cf4813095b39b41
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Trevor Parscal <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits