Javascript-форум (https://javascript.ru/forum/)
-   Общие вопросы Javascript (https://javascript.ru/forum/misc/)
-   -   вызов метода с прототипа (https://javascript.ru/forum/misc/31800-vyzov-metoda-s-prototipa.html)

bot87 21.09.2012 08:55

вызов метода с прототипа
 
function Construct1(x,y){
	var coords_x=x;
	var coords_y=y;
	this.pub=function(){
	alert(coords_x-coords_y);
	}
	}
Construct1.prototype.say=function(){
	alert(coords_x-coords_y);
	}	
obj=new Construct1(13,-9);
obj.pub();//good!!!
obj.say()//coords_x is not defined

Помогите исправить

vadim5june 21.09.2012 09:37

Цитата:

Сообщение от bot87
Помогите исправить

Можно исправить если только say внутри Construct1 определить
http://javascript.ru/tutorial/object...private-chleny

vashurin 21.09.2012 13:45

Цитата:

Сообщение от bot87 (Сообщение 205671)
function Construct1(x,y){
	var coords_x=x;
	var coords_y=y;
	this.pub=function(){
	alert(coords_x-coords_y);
	}
	}
Construct1.prototype.say=function(){
	alert(coords_x - coords_y);
	}	
obj=new Construct1(13,-9);
obj.pub();//good!!!
obj.say()//coords_x is not defined

Помогите исправить


function Construct1(x,y){
	this.coords_x=x;
	this.coords_y=y;
	this.pub=function(){
	alert(this.coords_x-this.coords_y);
	}
	}
Construct1.prototype.say=function(){
	alert(this.coords_x  -  this.coords_y);
	}	
obj=new Construct1(13,-9);
obj.pub();//good!!!
obj.say()//coords_x is not defined

this :)

bot87 21.09.2012 14:01

vadim5june,vashurin спасибо за помощь


Часовой пояс GMT +3, время: 09:53.