I run my interface like this, m1 just grabs the elementById and sets the onclick attribute to the function name.
Because I want to “instantiate an object” I create a public static method called
ControlSignIn.interface
which then creates and invokes my object like this:
new ControlSignIn().invoke();
Is this the best practice way to do this?
Min.m1( 'signin_button', ControlSignIn.interface );
break:
var ControlSignIn = function( )
{
var form_element = document.getElementById( 'signin' );
var response_element = document.getElementById( 'signin_response' );
var text_object = new Text( form_element );
var message_object = new Message( response_element );
this.invoke = function( )
{
if( Global.validate_input_on === 1 )
{
if( !text_object.checkEmpty() )
{
message_object.display( 'empty' );
return false;
}
if( !text_object.checkPattern( 'email' ) )
{
message_object.display( 'email' );
return false;
}
if( !text_object.checkPattern( 'pass' ) )
{
message_object.display( 'pass' );
return false;
}
}
AjaxNew.repeatUse( ajaxSerialize( form_element ) + '&ajax_type=signin_control', function( server_response_text ) { ajaxType( server_response_text, response_element, 'respond' ); } );
}
};
ControlSignIn.interface = function()
{
new ControlSignIn().invoke();
};
Mmm. there are a lot of global objects in there. Too much coupling, regardless of the language.
Not sure why you create a new instance of ControlSignIn and then call its methods. Also, assign to the prototype like you did for invoke. Not sure why you need this method at all to be honest.
To be honest, I have a faint idea what you are trying to do (it’s some sort of form validation, right?) but it’s all quite convoluted and I don’t even know where to start.