klass()

功能

创建一个新的 skylark 类型。

语法

langx.klass(props, parent, options)

参数

  • props
    要创建的类的属性
  • parent
    要创建的类的父类
  • options
    创建类的选项

范例

Example:

EventsHandler = langx.klass({
    init: function(elm) {
        this._target = elm;
        this._handler = {};
    },

    // add a event listener
    // selector Optional
    register: function(event, callback, options) {
        // Seperate the event from the namespace
        var parsed = parse(event),
            event = parsed.type,
            specialEvent = specialEvents[event],
            bindingEvent = specialEvent && (specialEvent.bindType || specialEvent.bindEventName);

        var events = this._handler;

        // Check if there is already a handler for this event
        if (events[event] === undefined) {
            events[event] = new EventBindings(this._target, bindingEvent || event);
        }

        // Register the new callback function
        events[event].add(callback, langx.mixin({
            ns: parsed.ns
        }, options)); // options:{selector:xxx}
    },

    // remove a event listener
    unregister: function(event, fn, options) {
        // Check for parameter validtiy
        var events = this._handler,
            parsed = parse(event);
        event = parsed.type;

        var listener = events[event];

        if (listener) {
            listener.remove(fn, langx.mixin({
        ns: parsed.ns
            }, options));
        }
    }
});