javascript - Is it possible to access the prototype variable GLOBALLY -
function person() {} person.prototype.getfullname = function(){ var name = "john micheal"; } var p1 = new person(); console.log(p1.getfullname());
here want access variable "name" other prototypes. possible?
if not, there other way ?
http://jsfiddle.net/kabeerrifaye/bcxqx1wj/
thanks in advance.
you should go javascript tutorials. recommend treehouse or codeschool.
anyways, there few possible options / interpretations of question.
if you're trying return value need use return
keyword. console.log
output name.
function person() {} person.prototype.getfullname = function(){ var name = "john micheal"; return name; } var p1 = new person(); console.log(p1.getfullname());
if want share value between functions need use this
keyword. in example can set value in setname
, retrieve getname
.
function person() {} person.prototype.getname = function(){ return this.name } person.prototype.setname = function(newname) { this.name = newname } var p1 = new person(); p1.setname('john'); console.log(p1.getname());
these hard concepts learn on own. recommend working through javascript tutorials learn fundamental concepts.
Comments
Post a Comment