The first statement which uses this ( line 2 ) errors with:
this is undefined
Verified the line number. Verified that this style of use works in another function called SMessage. Tried changing the argument name so it was not equal to the object property. Can’t figure out why it won’t make the assignment to this.tag_array. Verified tag_array1 was populated as an array of values.
var VBPaneInit = function ( tag_array1 ) {
this.tag_array = tag_array1;
this.initializeTags();
this.initializePages();
VBPaneInit.prototype.initializeTags = function( ) {
var element;
for ( element = 0; element < this.tag_array.length; element++ )
{
document.getElementById( this.tag_array[element] ).onclick = vDomPageFlip;
}
};
VBPaneInit.prototype.initializePages = function( ) {
if ( this.tag_array.length === 0 )
{
return;
}
var index, page_element;
for ( index = 0; index < this.tag_array.length; index++ )
{
page_element = document.getElementById( this.tag_array[index] + '_page' );
page_element.style.display = 'none';
}
vDomPageFlip( this.tag_array[0] );
};
};
The Call
VBPaneInit( tag_array );
For testing purposes reduce to :
var VBPaneInit = function( tag_array ) {
this.tag_array = tag_array;
}
Still no go.
Working Similar:
var SMessage = function ( element ) {
this.element = element;
SMessage.prototype.display = function( type ) {
this.element.innerHTML = this.messages[ type ];
};
SMessage.prototype.messages = {
name: 'Please enter a valid name',
email: 'Please enter a valid email',
pass: 'Please enter password, 6-40 characters',
url: 'Please enter a valid url',
title: 'Please enter a valid title',
tweet: 'Please enter a valid tweet',
empty: 'Please complete all fields',
same: 'Please make emails equal',
taken: 'Sorry, that email is taken',
validate: 'Please contact <a class="d" href="mailto:chris@host.com">support</a> to reset your password',
s_name: 'Please enter a valid name.',
s_email: 'Please enter a valid email.',
s_pass: 'Please enter password, 6-40 characters.',
s_url: 'Please enter a valid url.',
s_title: 'Please enter a valid title.',
s_tweet: 'Please enter a valid tweet.',
s_empty: 'Please complete all fields.',
s_same: 'Please make emails equal.',
s_taken: 'Sorry, that email is taken.',
s_validate: 'Please contact <a class="d" href="mailto:chris@host.com">support</a> to reset your password.'
};
};
There is no
thisbecause you’re not sayingnew VBPaneInit(tag_array), you need thenewto create an object.Then, your next problem is that you’re not building the prototype correctly in two different ways:
vBPaneInitis not the same asVBPaneInit, JavaScript is case sensitive.You should be doing something more like this: