开发者

javascript: assign function parameter if functioncall is a string?

Following example - the YoutubePlayer API

videoID.addEventListener('onStateChange', 'foo');

In the documentation they say, video.addEventListener(stri开发者_StackOverflow中文版ng: event, string: function). That means the first parameter is the event (in my case onStateChange) and the second parameter is the function that is getting called when the even is triggered.

This youtube sample is just a good example, I've alredy had this question a few times before. If the function to call is passed as a string, is there any chance to assign a a parameter to that function?

Imagine the function I want to call looks like this.

function foo(something) {
   console.log(something).
}

It's obviously not possible to add a parameter to the function call is it? Like…

videoID.addEventListener('onStateChange', 'foo(videoID)');

Thank you for your information and answers.


You could do something like:

videoID.addEventListener('onStateChange', function()
{
    foo(videoID);
});

...if I'm understanding you correctly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜