Both these ways work using the same call mechanism.
Obviously, I want to use the best way, but perhaps it is just a matter of preference?
Style-wise I like the Object Literal Notation because it provides enclosure.
Function Notation:
var TextProcessor = function()
{
};
TextProcessor.unEscape = function( second_split )
{
var element;
for( element in second_split )
{
second_split[element] = second_split[element].replace( '**', '*', 'g' );
second_split[element] = second_split[element].replace( '|*', '|', 'g' );
}
return second_split;
};
TextProcessor.pullBullet = function( text )
{
var pattern = /<(.+)_([a-z]){1}>$/;
return pattern.exec( text );
};
TextProcessor.pullDomain = function( text )
{
return text.match( /://(www.)?(.[^/:]+)/ )[2];
};
Object Literal Notation
/**
*TextProcessor
*/
var TextProcessor =
{
unEscape: function( text )
{
var index;
for( index in second_split )
{
text[index] = text[index].replace( '**', '*', 'g' );
text[index] = text[index].replace( '|*', '|', 'g' );
}
return second_split;
},
pullBullet: function( text )
{
var pattern = /<(.+)_([a-z]){1}>$/;
return pattern.exec( text );
},
pullDomain: function( text )
{
return text.match( /://(www.)?(.[^/:]+)/ )[2];
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…