SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,376
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    How to get a Javascript property

    Where is an online reference for every kind of property for Javascript? In other words, the "length" property of string.length will point to the number of characters in a string (I think). So where are all the properties like this for strings? Where do I look them up?

    For instance, if I go here, I'm not sure how to look them up: https://developer.mozilla.org/en-US/...ript/Reference
    Steve Husting

  2. #2
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,296
    Mentioned
    460 Post(s)
    Tagged
    8 Thread(s)
    I haven't found any truly reliable online resources. I'm happier with a book, such as JavaScript: the Definitive Guide.

  3. #3
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,862
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    http://www.ecma-international.org/pu...T/Ecma-262.pdf - the original source where David Flanagan got the information needed to write JavaScript: the Definitive Guide.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  4. #4
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,376
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thank you both!
    Steve Husting

  5. #5
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,997
    Mentioned
    219 Post(s)
    Tagged
    12 Thread(s)
    You are on the right track with the MDN site.
    This is where I go if I want to look stuff up.

    To answer your question, if you type "String" into the search box in the top right hand corner, the first two entries will be for string - the function which converts the given argument to a string and String - the global object.

    If you click on the second two of these results, you can see all of String's properties and methods.

  6. #6
    Non-Member
    Join Date
    Feb 2012
    Posts
    892
    Mentioned
    10 Post(s)
    Tagged
    0 Thread(s)
    Open up the Console in Developer Tools in any browser. For strings native methods, type
    Code:
    console.dir(String.prototype)
    You'll get a comprehensive hierarchical listing of every kind of property.

    https://developer.mozilla.org/en-US/...PI/console.dir

    If you want a more in-depth look at the global object, type
    Code:
    console.dir(window)
    You'll notice all the native objects, including those for the JavaScript types: Object, Array, String, Number, Boolean. Their prototype object lists the native methods. These native methods are available to every corresponding type you'll use, primitive or reference. It's called prototypal inheritance.

    What this means is that when you create a string variable
    Code:
    var s = "string";
    inferred s type is String
    Code:
    var s = String("string");
    or
    Code:
    var s = new String("string");
    String.constructor method is called to create the value "string". s prototype's is now String.prototype, and s inherits those methods, including length.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •