First, we need to create cache of keys which contains in second parameter of Ext.define:
(function () { var old = Ext4.define, del = [ 'extend', 'mixins', 'statics', 'strictMethods', 'constructor', 'init', 'notStrictMethods', 'initComponent' ], res; // save keys in cache and delete potentially unsafe keys window.StrictCache = {}; Ext4.define = function (name, data) { res = Ext4.Object.getKeys(data); if (data.statics) { if (Ext4.isArray(data.statics.notStrictMethods)) { del = Ext4.Array.merge(del, data.statics.notStrictMethods); } res = Ext4.Array.merge(res, Ext4.Object.getKeys(data.statics)); } res = Ext4.Array.unique(res); if (Ext4.isArray(data.notStrictMethods)) { del = Ext4.Array.merge(del, data.notStrictMethods); } Ext4.each(del, function (toDelete) { Ext4.Array.remove(res, toDelete); }); StrictCache[name] = res; return old.apply(this, arguments); }; })();
Next, we must to write mixin:
/** * @class Lib.StrictMixin * Mixin class for 'use strict' * @author guyfawkes * @docauthor guyfawkes */ Ext4.define('Lib.StrictMixin', { onClassMixedIn : function (mixedClass) { var fn; // mixedClass can be both class prototype or constructor (in this case we need to get function from its prototype) // please note we don't break loop when strictMethods were found: it must be both in 'statics' and non-static of ExtJS 4's class Ext4.each([mixedClass, mixedClass.prototype], function (obj, index) { fn = function(method) { if (Ext4.isFunction(obj[method])) { console && console.info( Ext4.String.format( '{0} found in {1} of {2}', method, (index ? 'constructor prototype' : 'prototype'), obj.$className ) ); obj[method] = new Function("'use strict';nreturn " + obj[method].toString())(); } }; // if we need to loop over all methods, get keys from cache (or we'll get functions from parent classes and got an error if (Ext4.isString(obj.strictMethods) && (obj.strictMethods === 'ALL') && Ext4.isString(obj.$className)) { Ext4.each(StrictCache[obj.$className], fn); } else { // if strictMethods is an array, loop over it if (Ext4.isArray(obj.strictMethods)) { Ext4.each(obj.strictMethods, fn); } } }); } });