Migrate from middleclass 2.x to 3.x
masterWhen upgrading to version 3.x, note the following breaking changes:
- No Global Variables:
classandObjectare no longer set on the global scope. You must userequireto access them. - Accessing
classandObject:- Use
local class = require 'middleclass'to get the class factory. - Access the base object via
class.Object.
- Use
- API Refactoring: The standalone functions
instanceOf,subclassOf, andincludeshave been replaced by methods on instances or static methods on theObjectclass.
Note on Parameter Order: When using the new Object static methods, the parameter order has changed compared to the 2.x standalone functions.
-- 1. Accessing the class factory and Object
local class = require 'middleclass'
local Object = class.Object
-- 2. Using the new method-based API (requires valid objects/classes)
obj:isInstanceOf(MyClass)
aClass:isSubclassOf(Object)
aClass:includes(aMixin)
-- 3. Using the Object static API (safe for any type, but note parameter order)
Object.isInstanceOf(obj, MyClass)
Object.isSubclassOf(aClass, Object)
Object.includes(aClass, aMixin)