I'm new to js world and find jquery declares many properties as methods which make me very uncomfortable.Such as $("#foo").parent() which i think should be a property.
I know that js can also define property so i want to try redefine these method to corresponding property.
Object.defineProperty($.fn,"parent",
{
get:function () {
return this.parent()
},
configurable:false,
enumerable:true
});
then i can use it like this $("#foo").parent
but i got a stackoverflow
jqueryplus.js:180 Uncaught RangeError: Maximum call stack size exceeded
at n.fn.init.get [as parent] (jqueryplus.js:180)
at n.fn.init.get [as parent] (jqueryplus.js:181)
at n.fn.init.get [as parent] (jqueryplus.js:181)
at n.fn.init.get [as parent] (jqueryplus.js:181)
at n.fn.init.get [as parent] (jqueryplus.js:181)
at n.fn.init.get [as parent] (jqueryplus.js:181)
at n.fn.init.get [as parent] (jqueryplus.js:181)
at n.fn.init.get [as parent] (jqueryplus.js:181)
at n.fn.init.get [as parent] (jqueryplus.js:181)
at n.fn.init.get [as parent] (jqueryplus.js:181)
What's happening here? In my mind, it should be possible for variables/property and methods to have the same name which i'm familiar with in other language such as c#,kotlin...
parentmethod takes an optional parameter, which your getter would not be capable of.