Форум Flasher.ru
Ближайшие курсы в Школе RealTime
Список интенсивных курсов: [см.]  
  
Специальные предложения: [см.]  
  
 
Блоги Правила Справка Пользователи Календарь Сообщения за день
 

Вернуться   Форум Flasher.ru > Архив Flasher.ru > Работа над сайтом > DHTML/JS/CSS

Версия для печати  Отправить по электронной почте    « Предыдущая тема | Следующая тема »  
Опции темы Опции просмотра
 
Создать новую тему  
Старый 12.11.2003, 22:57
realMakc вне форума Посмотреть профиль Отправить личное сообщение для realMakc Найти все сообщения от realMakc
  № 1  
realMakc
 
Аватар для realMakc

Регистрация: Oct 2002
Сообщений: 284
Отправить сообщение для realMakc с помощью ICQ
По умолчанию Загадка джейскриптовского ООП-а

Я постил этот вопрос не в одном месте сегодня, посему Вы не обидитесь если я тупо скопирую мессадж сюда, хотя он и на англицком. Тем более, что упоминаемая в нём дока тоже на англицком, и вообще Вы можете мне чего-то объяснить, только если Вы понимаете эти англицкие доки.

Итак, скрипт:
<SCRiPT>

function A()
{
alert( this.constructor )
}

a1 = new A() // displays A(), no prob.

A.prototype = undefined
a2 = new A() // displays Object(), why?

</SCRiPT>


According to JScript specification (http://msdn.microsoft.com/library/de...onstructor.asp),

"The constructor property contains a reference to the function that constructs instances of that particular object."

Here, A() definetly constructs a2, since we see its message during object construction, but the message itself is saying that constructor is Object(), not A(). According to mentioned specification,

"The constructor property is a member of the prototype of every object that has a prototype."

This is a tricky place. At the beginning, A() still has a prototype, therefore the "constructor" property of A() prototype (which should be - and actually is - A() ) gets displayed, when object a1 is created.

Later, we remove prototype (containing "constructor" property) from A(), therefore it could be expected that alert(this.constructor) after should display "undefined" or something.

However, latter doesn't happen: "constructor" does not have to be a property of A()'s prototype anymore exactly because A() doesn't have a prototype.

JScript specification gives one no clue, which object "constructor" is own property of, when "the function that constructs instances" (here, A()) does not have a prototype.

Hence the question: where is it coming from, and why it equals to Object() ?

Создать новую тему   Часовой пояс GMT +4, время: 00:56.
Быстрый переход
  « Предыдущая тема | Следующая тема »  

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.


 


Часовой пояс GMT +4, время: 00:56.


Copyright © 1999-2008 Flasher.ru. All rights reserved.
Работает на vBulletin®. Copyright ©2000 - 2026, Jelsoft Enterprises Ltd. Перевод: zCarot
Администрация сайта не несёт ответственности за любую предоставленную посетителями информацию. Подробнее см. Правила.