execute方法是Yuka js库中Trigger触发器对象的方法之一。该方法用于调用该触发器的所有回调函数。
trigger.execute( data );
const trigger = new Trigger();
function callback1( data ) {
console.log( "Callback 1 has been called with parameter: " + data );
}
function callback2( data ) {
console.log( "Callback 2 has been called with parameter: " + data );
}
trigger.add( callback1 );
trigger.add( callback2 );
trigger.execute( "Hello, world!" );
该示例将创建一个Trigger对象,并向其添加两个回调函数。然后调用execute方法,将"Hello, world!"作为参数传递给这两个回调函数。执行结果为:
Callback 1 has been called with parameter: Hello, world!
Callback 2 has been called with parameter: Hello, world!