Publish a method in JavaScript. Why is this syntax?

I studied TinyMCE code and came across this way of exposing public methods:

tinymce.extend(this, {
    execCommand : execCommand,
    queryCommandState : queryCommandState,
    queryCommandValue : queryCommandValue,
    addCommands : addCommands
});

What is the advantage of writing above if instead you can use the code below (with fewer lines of code and less execution time needed for the same task!)

this.execCommand = execCommand;
this.queryCommandState = queryCommandState;
this.queryCommandValue = queryCommandValue;
this.addCommands = addCommands;

Or even shorter, somewhere in the declaration of the object:

execCommand: execCommand,
queryCommandState: queryCommandState,
queryCommandValue: queryCommandValue,
addCommands: addCommands

Where is the catch?

+3
source share
1 answer

Well, one thing that jumps at me is the first example in which you have a method in which TinyMCE expects its arguments for its function extend.

extend, undefined, , . , , .

+2

All Articles