Hello, I hope this question is not confusing, but how can I call 2 functions in a single line and that it depends on another? Example:
function().function();
It's kind of like what JQuery does. Example:
$('h1').text('Hola mundo!');
My problem is that I have no idea how to do that and my biggest attempt to do it was the following:
let auto = 0
function stTxt (color, backgroundColor) {
document.onmouseup = function () {
const element = document.createElement('span')
element.setAttribute('id', `stElement${auto}`)
window
.getSelection()
.getRangeAt(0)
.surroundContents(element)
const selectedElement = document.getElementById(`stElement${auto}`)
selectedElement.style.color = color
selectedElement.style.backgroundColor = backgroundColor
auto++
function stSize (fontSize) {
const elementSpan = document.getElementById(`stElement${auto}`)
elementSpan.style.fontSize = fontSize
}
}
}
The problem with this is that by putting the functions like this, they would only be called in the following way according to the official javascript documentation:
function()();
The reason why I want to do this is that the second function I want to be only optional for the user but as you can see this function directly depends on the previous one because I would like to add more functionality to the main function if required.
It can be done in many ways, one of them is to return an object: