mmundiff
mmundiff

Reputation: 3951

Weird Object Error in Javascript

First, I'm not a javascript developer so I don't have a great deal of experience in this if any.

I have a footer I'm inserting into an HTML page using jQuery that has the following code in it that per the client "NEEDS TO BE THERE".

<script language="JavaScript"><!--
/************* DO NOT ALTER ANYTHING BELOW THIS LINE ! **************/
var s_code=s.t();if(s_code)document.write(s_code)//--></script>
<script language="JavaScript"><!--
if(navigator.appVersion.indexOf('MSIE')>=0)document.write(unescape('%3C')+'\!-'+'-')
//--></script>

I don;t really have to worry about anything except this s.t(); line of code. I need to write a dummy Object or whatever else and include it in the header that doesn't do anything per se except prevent a javascript error from occurring.

So really I need "s" the object to be instantiated and have a function "t" attached to it that basically does nothing.

Any help is appreciated. This isn't something I want to do but given the budget and project constraints of the client I just need for this to work without a javascritp error.

thanks if you can help.

Upvotes: -1

Views: 824

Answers (2)

Kobi
Kobi

Reputation: 138147

var s = {
   t: function(){}
};

See it in, hmm, action: http://jsbin.com/oboju

In case you're worried s is defined and don't want to override it, you can check for it first (this doesn't cover the case s.t is defined but isn't a function):

if(!s){ // check if s exists
  var s = [];
}
if(!s.t){ // check if s has t
  s.t = function(){};
}

Upvotes: 0

putolaruan
putolaruan

Reputation: 2054

Using javascript prototype:

function s () {
}

function doSomething () {
}

s.prototype.t = doSomething;

edit: typo

Upvotes: 1

Related Questions