javascript fails

M

Morten Snedker

If my question is off this group, please point me in the right
direction.

Here goes:

My scipt fails between alert-2 and alert-3 with

"Object doesn't support this property or method" (freely translated
from Danish).

Any idea what could be wrong?

The code is a rip-off from
http://xaprb.com/articles/number-formatting-demo.html.

<script language="javascript" type="text/javascript" >

function fNr(context){
alert("1");
var val = (context == null) ? new Number(this) : Math.abs(this);
alert("2");
var arr = val.round(2).toFixed(2).split(',');
alert("3");
arr[0] = (val < 0 ? '-' : '') + String.leftPad((val < 0 ?
arr[0].substring(1) : arr[0]), 1, '0');
alert("4");
arr[0] = Number.addSeparators(arr[0]);
alert("5");
arr[0] = Number.injectIntoFormat(arr[0].reverse(), '0###',
true).reverse();
alert("6");
arr[1] = Number.injectIntoFormat(arr[1], '00', false);
alert("7");
return arr.join(',');
}

</script>



Regards /Snedker
 
K

Kevin Spencer

In the context of your ripped-off version, "this" is the HTML document. In
the context of the script you ripped off, "this" is a JavaScript object,
specifically, the JavaScript Number object:

http://www.comptechdoc.org/independent/web/cgi/javamanual/javanumber.html

The author of the script has extended the Number object via prototyping.The
following tutorial should help you to understand how it works:

http://www.javascriptkit.com/javatutors/proto.shtml

--
HTH,

Kevin Spencer
Microsoft MVP
Logostician
http://unclechutney.blogspot.com

Parabola is a mate of plane.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top