How does javascript understand the following?

(obj.inner.print) () and (obj.inner.print = obj.inner.print) ()) how to understand?

var num = 10;
var obj = {
    num:8,
    inner: {
        num: 6,
        print: function () {
            console.log(this.num);
        }
    }
}
num = 888;
obj.inner.print(); // 6
var fn = obj.inner.print;
fn(); //888
(obj.inner.print)(); //6
(obj.inner.print = obj.inner.print)(); //888 
Feb.28,2021

(obj.inner.print)()

is actually

.
obj.inner.print()

and

(obj.inner.print = obj.inner.print)()

is an assignment operation, returns a function, and then calls this function


the first is to run the function, (function) (), runs the anonymous function itself. The second one you can imagine is that you eat drumsticks. You take drumsticks in your left hand and replace them with your right hand.

Menu