Javascript functions and objects using equal operator -
i trying understand javascript concepts https://developer.mozilla.org/en-us/docs/javascript/a_re-introduction_to_javascript . please see code below;
function personfullname() { homecoming this.first + ' ' + this.last; } function personfullnamereversed() { homecoming this.last + ', ' + this.first; } function person(first, last) { this.first = first; this.last = last; this.fullname = personfullname; this.fullnamereversed = personfullnamereversed; }
i confused why function personfullname() called
this.fullname = personfullname;
why not called like;
this.fullname = personfullname();
and same below;
this.fullnamereversed = personfullnamereversed;
i know functions objects in javascript unable understand concept?
because person
object assigning method, not results of function. reason doesn't phone call function.
this way can this.
var p = new person("matt", "m"); p.fullname(); // returns "matt m" p.fullnamereversed(); // returns "m, matt"
javascript function object equals operator-keyword
No comments:
Post a Comment