I have written a javascript client-object model code and I am calling it through the below line code from content editor webpart:

ExecuteOrDelayUntilScriptLoaded(getWebSiteData(sys), "sp.js");// throwing error

But it is throwing javascript error in init.js and other javascript functions are not working. Can someone tell me how to pass parameters to javascript client-model function?

  • Why don't you like to have your code as code formatted? In my option this makes the question clear. Jul 5, 2012 at 6:42

2 Answers 2


You can use an function as a delegate and then call your function with in.

ExecuteOrDelayUntilScriptLoaded(function () { alertThis("Hello World") }, "core.js");

function alertThis(value)

It is worth reading about closures, delegates and Anonymous functions in javascript to help understand the code.
SO - How does an anonymous function in javascript work
SO - How do javascript closures work
Mozzila Developer Network Closures

Any comments to help improve this answer would be helpful.

  • Fixed Line breaks between links.
    – JC Vivian
    Jun 28, 2012 at 11:22
  • @Vardhaman I still want to find a good MDN link for anonymous functions as its is more on topic
    – JC Vivian
    Jun 28, 2012 at 15:43

The answer suggested by JC Vivian works nicely, but in my opinion there's a cleaner, more readable way. You can create a function that returns the function that does what you need:

function dataGetterFor (param) {
    return function () {
ExecuteOrDelayUntilScriptLoaded(dataGetterFor(sys), "sp.js");

This causes dataGetterFor(sys) to be evaluated and ExecuteOrDelayUntilScriptLoaded to be called with an anonymous function. A shorter but less extensible way to achieve the same result is the one-liner

ExecuteOrDelayUntilScriptLoaded(function () { getWebSiteData(sys); }, "sp.js");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.