JSFiddle - React, Tailwind, and code Playground
CSS
* {
box-sizing:border-box;
}
.el {
display:block;
width:300px;
height:auto;
background:red;
padding:5px 0 10px 35px;
font-weight:bold;
}
JavaScript
// Rule 2
var div = document.createElement("div");
document.body.appendChild(div);
div.classList.add("el");
div.innerHTML +=
"<p>" + "Hello" + "</p>";
var func = function func() {
this.box.style.color = "white";
};
// Apply 'this' value, using ES6 spead operator
var number = [5, 4, 22, 35];
var math = function(args) {
return Math.max(...number);
};
var baz = {
box : div,
foo : func,
fee : function() {
return math.apply(null, arguments);
}
};
baz.foo(); // baz{}
console.log(baz.fee(number)); // 35
// Soft binding with one argument
var func1 = function func1() {
this.innerHTML +=
"<p>" + "Soft binding" + "</p>";
};
func1.call(baz.box);
// Soft binding with additional arguments via call. Using ES6 rest parameters.
var w = "with",
add = "additional",
args = "arguments";
var func2 = function func2(...theArgs) {
this.innerHTML +=
"<p>" + "Soft binding" + " " + theArgs[0] + " " + theArgs[1] + " " + theArgs[2] + "</p>";
};
func2.call(baz.box, w, add, args);
// first bind this and then invoke
var func3 = function fanc3(arg0, arg1) {
this.innerHTML+=
"<p>" + arg0 + " " + arg1 + "</p>";
};
var func3Caller = func3.bind(baz.box);
func3Caller("hard", "binding");