new eg.Component()
A class used to manage events and options in a component
컴포넌트의 이벤트와 옵션을 관리할 수 있게 하는 클래스
Browser Support
Browser | Version |
---|---|
Desktop - Internet Explorer | 7+ |
Desktop - Chrome | latest |
Desktop - Firefox | latest |
Desktop - Safari | latest |
Desktop - Edge | latest |
iOS | 7+ |
Andorid | 2.1+ (except 3.x) |
Methods
-
hasOn(eventName){Boolean}
-
Checks whether an event has been attached to a component.
컴포넌트에 이벤트가 등록됐는지 확인한다.
-
eventNameType: String
The name of the event to be attached
등록 여부를 확인할 이벤트의 이름
Returns:
Type Description Boolean Indicates whether the event is attached.이벤트 등록 여부
Example
var Some = eg.Class.extend(eg.Component,{ "some": function(){ this.hasOn("hi");// check hi event. } });
-
-
off(eventName, handlerToDetach){eg.Component}
-
Detaches an event from the component.
컴포넌트에 등록된 이벤트를 해제한다
-
eventNameType: eventName
The name of the event to be detached
해제할 이벤트의 이름
-
handlerToDetachType: function
The handler function of the event to be detached
해제할 이벤트의 핸들러 함수
Returns:
Type Description eg.Component An instance of a component itself컴포넌트 자신의 인스턴스
Example
var Some = eg.Class.extend(eg.Component,{ "hi": function(){}, "some": function(){ this.off("hi",this.hi); //detach event } });
-
-
on(eventName, handlerToAttach){eg.Component}
-
Attaches an event to a component.
컴포넌트에 이벤트를 등록한다.
-
eventNameType: eventName
The name of the event to be attached
등록할 이벤트의 이름
-
handlerToAttachType: function
The handler function of the event to be attached
등록할 이벤트의 핸들러 함수
Returns:
Type Description eg.Component An instance of a component itself컴포넌트 자신의 인스턴스
Example
var Some = eg.Class.extend(eg.Component,{ "hi": function(){}, "some": function(){ this.on("hi",this.hi); //attach event } });
-
-
once(eventName, handlerToAttach){eg.Component}
-
Executed event just one time.
이벤트가 한번만 실행된다.
-
eventNameType: eventName
The name of the event to be attached
등록할 이벤트의 이름
-
handlerToAttachType: function
The handler function of the event to be attached
등록할 이벤트의 핸들러 함수
Returns:
Type Description eg.Component An instance of a component itself컴포넌트 자신의 인스턴스
Example
var Some = eg.Class.extend(eg.Component,{ "hi": function(){ alert("hi"); }, "thing": function(){ this.once("hi",this.hi); } }); var some = new Some(); some.thing(); some.trigger("hi"); // fire alert("hi"); some.trigger("hi"); // Nothing happens
-
-
option(key, value){eg.Component|Object}
-
Sets options in a component or returns them.
컴포넌트에 옵션을 설정하거나 옵션을 반환한다
-
keyType: String
The key of the option
옵션의 키
-
value optionalType: Object
The option value that corresponds to a given key
키에 해당하는 옵션값
Returns:
Type Description eg.Component | Object An instance, an option value, or an option object of a component itself.
- If both key and value are used to set an option, it returns an instance of a component itself.
- If only a key is specified for the parameter, it returns the option value corresponding to a given key.
- If nothing is specified, it returns an option object.컴포넌트 자신의 인스턴스나 옵션값, 옵션 객체.
- 키와 값으로 옵션을 설정하면 컴포넌트 자신의 인스턴스를 반환한다.
- 파라미터에 키만 설정하면 키에 해당하는 옵션값을 반환한다.
- 파라미터에 아무것도 설정하지 않으면 옵션 객체를 반환한다.Example
var Some = eg.Class.extend(eg.Component, { construct: function(options){ this.options = options; // You have to set this.options. } }); var some = new Some({ "foo": 1, "bar": 2, }); some.option("foo"); // return 1 some.option("foo",3); // return some instance some.option(); // return options object. some.option({ "foo" : 10, "bar" : 20, "baz" : 30 }); // return some instance.
-
-
trigger(eventName, customEvent){Boolean}
-
Triggers a custom event.
커스텀 이벤트를 발생시킨다
-
eventNameType: String
The name of the custom event to be triggered
발생할 커스텀 이벤트의 이름
-
customEventType: Object
Event data to be sent when triggering a custom event
커스텀 이벤트가 발생할 때 전달할 데이터
Returns:
Type Description Boolean Indicates whether the event has occurred. If the stop() method is called by a custom event handler, it will return false and prevent the event from occurring.이벤트 발생 여부. 커스텀 이벤트 핸들러에서 stop() 메서드를 호출하면 'false'를 반환하고 이벤트 발생을 중단한다.
Example
var Some = eg.Class.extend(eg.Component,{ "some": function(){ this.trigger("hi");// fire hi event. } });
-