The Artima Developer Community
Sponsored Link

Java Buzz Forum
JavaScript and dir()

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Carlos Villela

Posts: 116
Nickname: cvillela
Registered: Jun, 2003

Carlos Villela is a Java developer working mostly with web technologies and AOP.
JavaScript and dir() Posted: Jul 4, 2003 7:54 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Carlos Villela.
Original Post: JavaScript and dir()
Feed Title: That's sooo '82!
Feed URL: http://www.jroller.com/rss/cv?catname=Technical
Feed Description: Carlos Villela's weblog. Everyday life, everyday software development, everyday musings.
Latest Java Buzz Posts
Latest Java Buzz Posts by Carlos Villela
Latest Posts From That's sooo '82!

Advertisement
Sometimes I miss Python's dir() function a lot. It's so comfortable to use it while programming on an interpreter shell! I wonder why JavaScript doesn't come with something similar as a built-in function.

Experimenting a little, I came up with this simple, yet very handy code:

function (o) {
    r = new java.util.ArrayList();
    for (i in o) {
        r.add(i);
    }
    return r;
}

This has the same effect as Python's dir(), and can list the properties, methods and functions of any Java object:

js> dir("")
[]

js> dir(new java.lang.String());
[toUpperCase, getBytes, getChars, replaceAll, equalsIgnoreCase, matches, indexOf, notifyAll, toCharArray, length, concat, intern, charAt, subSequence, equals, notify, class, contentEquals, wait, split, compareTo, compareToIgnoreCase, toString, replaceFirst, hashCode, toLowerCase, trim, lastIndexOf, endsWith, regionMatches, replace, substring, startsWith, getClass]

js> dir(java.lang.String)
[copyValueOf, CASE_INSENSITIVE_ORDER, valueOf]


Interesting to note that JavaScript strings don't get any properties, methods or functions listed. I'll have to take a better look at this and understand what's happening. For now, I've got a kick-ass interpreted Java object browser...

Read: JavaScript and dir()

Topic: JDO Introduction-JBoss Previous Topic   Next Topic Topic: OFBiz Persistence Revisited

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use