Javascript-форум (https://javascript.ru/forum/)
-   Общие вопросы Javascript (https://javascript.ru/forum/misc/)
-   -   Не понимаю код, строчку... (https://javascript.ru/forum/misc/17287-ne-ponimayu-kod-strochku.html)

АrnowtАА 13.05.2011 11:44

Не понимаю код, строчку...
 
Не могу полностью понять строчку
var objBody = this.doc.getElementsByTagName("body").item(0);
doc это эквивалент document?
Что такое item(0)?
зы
Гугл не помог:( .

walik 13.05.2011 13:07

Цитата:

Сообщение от АrnowtАА
doc это эквивалент document?

Вроде нет.

Цитата:

Сообщение от АrnowtАА
Что такое item(0)?

Получает нулевой (самый первый, отсчет элементов с нуля начинается) элемент.

Sweet 13.05.2011 13:18

А что, document.body где-то не поддерживается???
Цитата:

Сообщение от АrnowtАА
Что такое item(0)?

Насколько я понимаю, отличие такое:
document.getElementsByTagName("body")[1]; //Вернет undefined
document.getElementsByTagName("body").item(1); //Вернет null

АrnowtАА 13.05.2011 13:22

Цитата:

Сообщение от walik (Сообщение 104484)
Вроде нет.

Что тогда такое doc?:help:

Kolyaj 13.05.2011 13:24

По смыслу это сохранённая ссылка на document. По факту может быть всё, что угодно.

walik 13.05.2011 13:25

Цитата:

Сообщение от АrnowtАА
Что такое doc?

Ну в данном случае это свойство элемента this. А хз что в this и в doc.
Может там лежит копия объекта document))
blablabla
<script>
var doc = document;
alert(doc.body.innerHTML);
</script>

АrnowtАА 13.05.2011 13:47

Цитата:

Сообщение от walik (Сообщение 104490)
Ну в данном случае это свойство элемента this. А хз что в this и в doc.
Может там лежит копия объекта document))
blablabla
<script>
var doc = document;
alert(doc.body.innerHTML);
</script>

Я тоже так думал, но в коде нет подобной строчки var doc = document;
Привожу ниже весь код до строчки this.doc.getElementsByTagName("body").item(0).
Array.prototype.removeDuplicates = function () { for (var i = 1; i < this.length; i++) { if (this[i][0] == this[i-1][0]) { this.splice(i,1); } } }

Array.prototype.empty = function () { for (var i = 0; i <= this.length; i++) { this.shift(); } }

String.prototype.trim = function () { return this.replace(/^\s+|\s+$/g, ''); }
function LyteBox() {
		this.theme			= 'red';	

		this.hideFlash			= true;		

		this.outerBorder		= true;		

		this.resizeSpeed		= 8;		

		this.maxOpacity			= 80;		/

		this.navType			= 1;		// 1 = "Prev/Next" buttons on top left and left (default), 2 = "<< prev | next >>" links next to image number

		this.autoResize			= true;		

		this.doAnimations		= true;		

		this.borderSize			= 12;
	
		this.slideInterval		= 4000;		

		this.showNavigation		= true;		

		this.showClose			= true;		

		this.showDetails		= true;		

		this.showPlayPause		= true;		

		this.autoEnd			= true;		

		this.pauseOnNextClick	= false;	

        this.pauseOnPrevClick 	= true;		
	if(this.resizeSpeed > 10) { this.resizeSpeed = 10; }
	if(this.resizeSpeed < 1) { resizeSpeed = 1; }
	this.resizeDuration = (11 - this.resizeSpeed) * 0.15;
	this.resizeWTimerArray		= new Array();

	this.resizeWTimerCount		= 0;

	this.resizeHTimerArray		= new Array();

	this.resizeHTimerCount		= 0;

	this.showContentTimerArray	= new Array();

	this.showContentTimerCount	= 0;

	this.overlayTimerArray		= new Array();

	this.overlayTimerCount		= 0;

	this.imageTimerArray		= new Array();

	this.imageTimerCount		= 0;

	this.timerIDArray			= new Array();

	this.timerIDCount			= 0;

	this.slideshowIDArray		= new Array();

	this.slideshowIDCount		= 0;

	this.imageArray	 = new Array();

	this.activeImage = null;

	this.slideArray	 = new Array();

	this.activeSlide = null;

	this.frameArray	 = new Array();

	this.activeFrame = null;

	this.checkFrame();

	this.isSlideshow = false;

	this.isLyteframe = false;

	/*@cc_on

		/*@if (@_jscript)

			this.ie = (document.all && !window.opera) ? true : false;

		/*@else @*/

			this.ie = false;

		/*@end

	@*/

	this.ie7 = (this.ie && window.XMLHttpRequest);	

	this.initialize();

}

LyteBox.prototype.initialize = function() {

	this.updateLyteboxItems();

	var objBody = this.doc.getElementsByTagName("body").item(0);	

.....

Sweet 13.05.2011 16:13

Вот это:
Array.prototype.empty = function () { for (var i = 0; i <= this.length; i++) { this.shift(); } }
ваще fail аффтора! Тупая и долгая функция, бессмысленно срущая в прототип:)
А по теме:
1. Почему бы не написать console.log(this) и там не посмотреть?
2. Этот doc может определяться и ниже, типа:
LyteBox.prototype.doc = document;

АrnowtАА 13.05.2011 18:45

Ясн. Спасибо. Я всё понял


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