![]() |
|
||||||||||
|
|||||
|
Я постил этот вопрос не в одном месте сегодня, посему Вы не обидитесь если я тупо скопирую мессадж сюда, хотя он и на англицком. Тем более, что упоминаемая в нём дока тоже на англицком, и вообще Вы можете мне чего-то объяснить, только если Вы понимаете эти англицкие доки.
Итак, скрипт: <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, время: 03:11. |
|
|
« Предыдущая тема | Следующая тема » |
| Опции темы | |
| Опции просмотра | |
|
|