By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,045 Members | 1,339 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,045 IT Pros & Developers. It's quick & easy.

2 questions in JS

P: n/a
Isa
Hi every one !

1. I would like to know why \t and \n are not recognize. Is there a
version of Js that we must specify ? Also why document.write(...) and
writeln(...) give the same result ? Isn't supposed to have a newline
with writeln?

2. I would like to know more about Object oriented in JS. Here is my
code and I would like to know why it's not working? What am I doing
wrong ?

function Rectangle(l, h) { // constructor
this.largeur = l;
this.hauteur = h;
}

var rect1 = new Rectangle(2,4);
document.writeln("area of rect1 " + rect1.area( ) ); //<- area is not
called or accessed :-(

function area( ) {
return this.largeur * this.hauteur;
}

Thank you very much !

Sep 27 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a

Isa wrote:
Hi every one !

1. I would like to know why \t and \n are not recognize. Is there a
version of Js that we must specify ? Also why document.write(...) and
writeln(...) give the same result ? Isn't supposed to have a newline
with writeln?
The writeln method is the same as the write method, except the writeln
method appends a newline character to the end of the output. HTML
ignores the newline character, except within certain tags such as the
PRE tag. For example:

<pre>
<script type = "text/javascript">
document.writeln("hello");
document.writeln("world");
</script>
</pre>
2. I would like to know more about Object oriented in JS. Here is my
code and I would like to know why it's not working? What am I doing
wrong ?

function Rectangle(l, h) { // constructor
this.largeur = l;
this.hauteur = h;
}

var rect1 = new Rectangle(2,4);
document.writeln("area of rect1 " + rect1.area( ) ); //<- area is not
called or accessed :-(

function area( ) {
return this.largeur * this.hauteur;
}
It is not working because your area() method is not a member of
Rectangle. Try the following instead:

function Rectangle(l, h)
{
this.largeur = l;
this.hauteur = h;
}

Rectangle.prototype.area = function()
{
return this.largeur * this.hauteur;
}

var rect1 = new Rectangle(2, 4);

alert("Area of rect1: " + rect1.area());

Sep 27 '06 #2

P: n/a
JRS: In article <11*********************@m73g2000cwd.googlegroups. com>,
dated Wed, 27 Sep 2006 10:04:44 remote, seen in
news:comp.lang.javascript, web.dev <we********@gmail.composted :
>
Isa wrote:
>1. I would like to know why \t and \n are not recognize. Is there a
version of Js that we must specify ? Also why document.write(...) and
writeln(...) give the same result ? Isn't supposed to have a newline
with writeln?

The writeln method is the same as the write method, except the writeln
method appends a newline character to the end of the output. HTML
ignores the newline character, except within certain tags such as the
PRE tag.
Newline is not ignored; it counts as whitespace, a separator, in
ordinary HTML.

It is well to generate a reasonable number of newlines in script-
generated HTML, if there is any chance that it will be read by a human,
a validator, etc.

It's a good idea to read the newsgroup and its FAQ. See below.
--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://www.jibbering.com/faq/>? JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Sep 27 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.