Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > 2 questions in JS

Reply
Thread Tools

2 questions in JS

 
 
Isa
Guest
Posts: n/a
 
      09-27-2006
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 !

 
Reply With Quote
 
 
 
 
web.dev
Guest
Posts: n/a
 
      09-27-2006

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());

 
Reply With Quote
 
 
 
 
Dr John Stockton
Guest
Posts: n/a
 
      09-27-2006
JRS: In article <(E-Mail Removed). com>,
dated Wed, 27 Sep 2006 10:04:44 remote, seen in
news:comp.lang.javascript, web.dev <(E-Mail Removed)> posted :
>
>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.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Few Questions (HW questions already answered by me) padh.ayo@gmail.com C Programming 10 12-06-2006 05:48 PM
Malloc and free questions - learner questions pkirk25 C Programming 50 10-04-2006 02:22 PM
Questions on Canon 300D and etc. questions regarding digital photography Progressiveabsolution Digital Photography 12 03-24-2005 05:18 PM
Newbie questions - Couple of VC++ questions regarding dlls and VB6 Ali Syed C Programming 3 10-13-2004 10:15 PM
Re: Questions....questions....questions Patrick Michael A+ Certification 0 06-16-2004 04:53 PM



Advertisments