触发器 (Trigger) 的 toJSON 方法返回一个 JSON 对象,其中包含触发器的各种属性。
trigger.toJSON()
该方法将返回一个 JSON 字符串,其中包含以下属性:
属性名 | 类型 | 描述 |
---|---|---|
type | string | 触发器的类型 |
event | string | 触发器的事件名称 |
selector | string | 触发器的选择器 |
callback | function | 触发器的回调函数 |
options | object | 触发器的选项参数 |
const trigger = new yuka.Trigger('click', '#button', () => console.log('Button clicked.'), { once: true });
const json = trigger.toJSON();
console.log(json);
// Output:
// {
// "type": "Trigger",
// "event": "click",
// "selector": "#button",
// "callback": "() => console.log('Button clicked.')",
// "options": { "once": true }
// }