Skip to content

Instantly share code, notes, and snippets.

@ColinCampbell
Created February 13, 2011 21:19
Show Gist options
  • Select an option

  • Save ColinCampbell/825143 to your computer and use it in GitHub Desktop.

Select an option

Save ColinCampbell/825143 to your computer and use it in GitHub Desktop.
diff --git a/frameworks/runtime/core.js b/frameworks/runtime/core.js
index 67bef70..a852a22 100644
--- a/frameworks/runtime/core.js
+++ b/frameworks/runtime/core.js
@@ -756,8 +756,37 @@ SC.mixin(/** @scope SC */ {
stringsFor: function(lang, strings) {
SC.mixin(SC.STRINGS, strings);
return this ;
- }
+ },
+
+ // ..........................................................
+ // DEPRECATION SUPPORT
+ //
+
+ /**
+ Creates a computed property for use on SC.Object that will raise
+ a warning if a property is get or set.
+ */
+ deprecated: function(msg) {
+ // we only want to do this if we're in debug mode, otherwise return an empty function
+ if (SC.buildMode !== 'debug' || console.warn === undefined) return SC.K;
+
+ return function(key, value) {
+ // fast path: we're dealing with a property labelled as a deprecated
+ if (SC.kindOf(this, SC.Object) && key && this.hasOwnProperty(key) && this[key].isProperty) {
+ console.warn(msg || "%@.%@ is deprecated. Please remove references to it.".fmt(this, key));
+ } else {
+ // find the function
+ for (key in this) {
+ if (!this.hasOwnProperty(key)) continue;
+ if (this[key] === arguments.callee) {
+ console.warn(msg || "%@.%@() is deprecated. Please remove references to it.".fmt(this, key));
+ break;
+ }
+ }
+ }
+ };
+ }
}); // end mixin
myObject = SC.Object.create({
myProperty: SC.deprecated().property(),
myMethod: SC.deprecated()
});
myObject.get('myProperty'); // raises a warning in the browser console
myObject.myMethod(); // also raises a warning
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment