A friend of mine has a popular open source JavaScript library which is quite well used in the community. He is now going through a process of refactoring and applying best practices and conventions and is wanting to upper case all constructor functions. So in the past where he may have defined a chart
object, he now wants it to be called Chart
to stick with convention.
Because the library is well used, he would rather warn devs when they use the old function names and eventually deprecate them.
I've recommended using a helper function :
var ObsoleteWithReplacement = function(replacementFunction, oldFnName, newFnName) {
var wrapper = function() {
console.warn("WARNING! Obsolete function called. Function '" + oldFnName + "' has been deprecated, please use the new '" + newFnName + "' function instead!");
replacementFunction.apply(this, arguments);
}
wrapper.prototype = replacementFunction.prototype;
return wrapper;
}
Which could be called as follows : http://jsfiddle.net/rLNep/1/
Is this a good way to go about it? Can you recommend a better way?
replacementFunction
to ensure its compatible with closure classes and prototypical ones. If this is only for prototypical class constructors you may want to choose a better name – megawac Feb 12 '14 at 17:56