SLB: Notes – JS: Classes
Requirements
- Consistent access to base object (
SLBglobal variable) - Support for methods/properties
- Consistent access to utility/helper methods/properties (prefix, context, etc.)
- Organized structure
- Extendible – Attach members/data to objects
- e.g.
SLB(base object),SLB.util(utility object),SLB.View(view controller), etc.
Implementation (Options)
- Current: Object literals with
extendmethod - Define methods in object declaration
-Object properties cannot reference self via this (referenceswindowobject)- Less modular code
+Simple declarations- Constructor function
- Objects are instances of base class definition
- Base constructor defines standard properties/methods (utilities, etc.)
SLB = new Base();
- All objects have direct access to standard methods/properties (
SLB.View.util.get_prefix();) ?Better than single base object with properties/methods (SLB.View.base.util references SLB.util)A:Yes- Will need to wrap initialization and attachment of new members into single method
- e.g.
SLB.attach('View', {data}); ?Method name? – currentlyextend, but may conflict withClass.extend()(Inheritance)- Single method – 2 modes (based on parameters)
SLB.extend('View', data)(2 parameters)- Add
Viewmember toSLBobject - Create new instance of base class inherited by
Viewobject data (object)– Properties/methods for new memberSLB.extend(obj)(1 parameter)- Extends
SLBobject and returns new instance +Simple+Single method for both related functionalities- One version simply adds it to global object
-Confusion: Better to have separate methods for sake of clarity?extend: Create new class inheriting base classattach: Add member to object (creating new class that inherits base class)- Structure
- Class Definitions
- Base
- Utility/Helper methods
- References base object for instance properties (
prefix, etc.) - Member attachment functionality
- Standard properties/methods
- Core
- Extends Base class
- Functionality specific to core object
- Instance Objects
- Core (
SLB) - Base instance for all other members to be attached to
- Members
- View Controller (
SLB.View) - Lightbox functionality controller
SLB.attach('View', obj class_definition)- New
Viewclass created (extends Base class) +Access to standard properties/methods without having to “travel” to Core (SLB) object- Components (viewers, groups, etc.)
- Attached via
SLB.View.Viewer = SLB.View.extend(obj class_definition)