Actually your constructor is working fine. But you should not use document.write
in your code. Instead you can append the value to a html tag, using either .append()
.html()
or .text()
methods. Also there should be a small change in your sayName()
method, Css should apply before return
. Otherwise it will not hit on those lines of code.
var SEP = SEP || {};
SEP.person = function (name) {
this.name = name
this.sayName = sayName
function sayName() {
$('body').css('background', 'red');
return this.name;
}
}
var bob = new SEP.person("bob");
word = bob.sayName();
$("span").text(word);