3

Possible Duplicate:
How does basic object/function chaining work in javascript?

Is there a way to make native function chainable?

For example, I want to do this:

var ele = document
            .createElement("div")
            .setAttribute("id", "foo")
            .focus();

instead of this:

var ele = document.createElement("div");
ele.setAttribute("id", "foo");
ele.focus();

Is there a way to do that? If it is possible, then it will definitely save me a lot of typing works.

Community
  • 1
  • 1
Derek 朕會功夫
  • 92,235
  • 44
  • 185
  • 247

0 Answers0