2 questions in JS

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Isa

    2 questions in JS

    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.writel n("area of rect1 " + rect1.area( ) ); //<- area is not
    called or accessed :-(

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

    Thank you very much !

  • web.dev

    #2
    Re: 2 questions in JS


    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.writel n("hello");
    document.writel n("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.writel n("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.proto type.area = function()
    {
    return this.largeur * this.hauteur;
    }

    var rect1 = new Rectangle(2, 4);

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

    Comment

    • Dr John Stockton

      #3
      Re: 2 questions in JS

      JRS: In article <1159376683.809 230.16640@m73g2 000cwd.googlegr oups.com>,
      dated Wed, 27 Sep 2006 10:04:44 remote, seen in
      news:comp.lang. javascript, web.dev <web.dev.cs@gma il.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.c om/faq/>? JL/RC: FAQ of news:comp.lang. javascript
      <URL:http://www.merlyn.demo n.co.uk/js-index.htmjscr maths, dates, sources.
      <URL:http://www.merlyn.demo n.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.

      Comment

      Working...