A question about Object Class

I got a question about Object class in AS3 recently.
I typed some testing codes as following:
var cls:Class = Object;
var cst:* = Object.prototype.constructor;
trace( cls === cst); // true
so cls & cst are the same thing ( the Object ).
var obj:Object = new Object();
var cst2:* = obj.constructor.constructor;
var cst3:* = obj.constructor.constructor.c.constructor;
var cst5:* = Object.prototype.constructoronstructor;
var cst4:* = Object.prototype.constructor.constructor.constructor;
var cst6:* = cls.constructor;
trace(cst2 === cst3 && cst3 === cst4 && cst4 === cst5 && cst5 === cst6); //true
trace( cst == cst2) // false
I debugged into these codes and found that cst & cst2 had the same content but not the same object,
so why cst & cst2 don't point to the same object?
Also, I can create an object by
" var obj:Object = new cst();"
but
" var obj:Object = new cst2();"
throws an exception said that cst2 is not a constructor.
Anyone can help? many thanks!

I used "describeType" and found that "cst2" is actually "Class" class.
So,
trace(cst2 === Class); // true
That's what I want to know, Thank you.

Similar Messages

  • LDAP BC QUESTION ABOUT OBJECT CLASSES

    Hi
    i am working with a bpel and its ldap-bc, when i create an entry in my ldap through the bpel it has all the object classes from the attributes i set. for example if i set cn and sn attributes then my entry has the object class person; i want to know if there is any way of setting object classes to my entry on the ldap, even if i am not setting any attributes; for example if i only set the cn and sn attributes using the bpel, i still can tell the entry that it can has another objectclass like iplanet-am-user-service with out setting any of its attributes.
    thanks for your help

    Actually, I'm not getting duplicate objects, but I like to get rid of
    doubles in one particular column.
    For example if I had a table as follows:
    Table DESC
    int pkid
    String description
    description can contain duplicate entries, I want to query as follows:
    select distinct description from DESC
    How could I write a query which retrieves all tuples in a table, but removes
    duplicate from a specific column?
    Thanks.
    Andreas.
    Abe White wrote:
    How does the engine use DISTINCT automatically?It detects whether joins are made such that duplicate rows might be
    returned from the JDOQL filter, and if so adds a DISTINCT.
    What I basically want to do is to remove any doubles I get from the
    query. When I turn logging on to see the sql statement, I only get a
    SELECT without the DISTINCT keyword.You shouldn't be getting doubles. If you are, could you please post the
    offending JDOQL filter and give some description of the schema and/or
    object model? There is a bug in Kodo in which some queries involving OR
    clauses and joins are not made DISTINCT when they should be, but it has
    been resolved for our upcoming 2.5 release.
    Is there also a way I can specify GROUP BY?No, JDOQL does not have an equivalent to GROUP BY.

  • Question about inner class - help please

    hi all
    i have a question about the inner class. i need to create some kind of object inside a process class. the reason for the creation of object is because i need to get some values from database and store them in an array:
    name, value, indexNum, flag
    i need to create an array of objects to hold those values and do some process in the process class. the object is only for the process class that contains it. i am not really certain how to create this inner class. i tried it with the following:
    public class process{
    class MyObject{}
    List l = new ArrayList();
    l.add(new MyObject(....));
    or should i create the object as static? what is the benifit of creating this way or static way? thanks for you help.

    for this case, i do need to create a new instance of
    this MyObject each time the process is running with a
    new message - xml. but i will be dealing with the case
    where i will need a static object to hold some
    property values for all the instances. so i suppose i
    will be using static inner class for that case.The two situations are not the same. You know the difference between instance variables and static variables, of course (although you make the usual sloppy error and call them static objects). But the meaning of "static" in the definition of an inner class is this: if you don't declare an inner class static, then an instance of that inner class must belong to an instance of its containing class. If you do declare the inner class static, then an instance of the inner class can exist on its own without any corresponding instance of the containing class. Obviously this has nothing to do with the meaning of "static" with respect to variables.

  • Question about abstract classes and instances

    I have just read about abstract classes and have learned that they cannot be instantiated.
    I am doing some exercises and have done a class named "Person" and an abstract class named "Animal".
    I want to create a method in "Person" that makes it possible to set more animals to Person objects.
    So I wrote this method in class Person and compiled it and did not get any errors, but will this work later when I run the main-method?
    public void addAnimal(Animal newAnimal)
         animal.add(newAnimal);
    }Is newAnimal not an instance?

    Roxxor wrote:
    Ok, but why is it necessary with constructors in abstract classes if we don�t use them (because what I have understand, constructors are used to create objects)?Constructors don't create objects. The new operator creates objects. An object's c'tor is invoked after the object has already been created. The c'tors job is to initialize the newly-created object to a valid state. Whenever a child object is created, the parent's c'tor is run before the child's c'tor, so that by the time we're inside the child's c'tor, setting up the child's state, we know that the parent (or rather the "parent part" of the object we're initializing) is in a valid state.
    Constructor rules:
    1) Every class has at least one ctor.
    1.1) If you do not define an explicit constructor for your class, the compiler provides a implicit constructor that takes no args and simply calls super().
    1.2) If you do define one or more explicit constructors, regardless of whether they take args, then the compiler no longer provides the implicit no-arg ctor. In this case, you must explicitly define a public MyClass() {...} if you want one.
    1.3) Constructors are not inherited.
    2) The first statement in the body of any ctor is either a call to a superclass ctor super(...) or a call to another ctor of this class this(...) 2.1) If you do not explicitly put a call to super(...) or this(...) as the first statement in a ctor that you define, then the compiler implicitly inserts a call to super's no-arg ctor super() as the first call. The implicitly called ctor is always super's no-arg ctor, regardless of whether the currently running ctor takes args.
    2.2) There is always exactly one call to either super(...) or this(...) in each constructor, and it is always the first call. You can't put in more than one, and if you put one in, the compiler's implicitly provided one is removed.

  • Question about handing classes in Objective-C

    Greetings -- I'm pretty new to Objective-C. I do have a few apps out in the app store, but they were simple one-form apps where I was able to dump everything into the main class and be happy with it.
    This new project I'm working on, is huge in comparison. Over 25 views, accessible through TableView driven menus.
    I was able to get all of the menus working, each launching a separate view NIB file (so far, just a label to show me that it's done, but I got that part working.)
    Now what I'm trying to do, is add a "click" sound when a row is selected. But I'm wanting to do this in a separate class, so each .m file can instantiate it's own version of the logic instead of having the same code 29 times.
    So, this is what I've done:
    Click.h
    #import <Foundation/Foundation.h>
    #import <AudioToolbox/AudioToolbox.h>
    @interface Click : NSObject
    SystemSoundID soundID;
    -(void) playClick;
    @end
    Click.m
    #import "Click.h"
    @implementation Click
    -(id) init
    self = [super init];
    NSString *path = [[NSBundle mainBundle] pathForResource:@"click" ofType:@"wav"];
    AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:path], &soundID);
    return self;
    -(void) playClick
    AudioServicesPlaySystemSound (soundID);
    @end
    RootViewController.h
    #import <UIKit/UIKit.h>
    #import "Click.h"
    @interface RootViewController : UITableViewController <UITableViewDelegate, UITableViewDataSource>
    NSArray *controllers;
    Click *clicker;
    @property (nonatomic, retain) NSArray *controllers;
    @property (nonatomic, retain) Click *clicker;
    @end
    RootViewController.m
    #import "RootViewController.h"
    @implementation RootViewController
    @synthesize controllers, clicker;
    - (void)viewDidLoad
    Click *newClicker = [[Click alloc] init];
    clicker = newClicker;
    [newClicker release];
    self.title = @"Main Menu";
    - (void)dealloc {
    [controllers release];
    [clicker release];
    [super dealloc];
    #pragma mark Table View Delegate Methods
    -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    [clicker playClick];
    I cut out the code pieces regarding the TableView that I know works, and tried showing only the parts that I've added to make the sound.
    What I've tried, is when the RootViewController is created, it has a SystemSoundID type variable defined with it named clicker. Then as part of "viewDidLoad", instantiate an instance of the class and have it automatically populate the variable "soundID". Then during "didSelectRowAtIndexPath", I want the "playClick" method of "clicker" to be run, but at this point the app seems to get caught in some sort of perma-loop, and I have to "STOP"/"Home" out of it.
    I'm hoping the problem is my rookie-status at using Objective-C objects, and the solution jumps out at you veterans, and then whatever problem I am having won't be duplicated when I create additional classes that I'd want to merge into my ViewController logic.
    Hope I've made everything clear. If anyone has questions, I'll be checking for replies
    Thanks.

    Dragon's Nest wrote:
    Is it preferred to init a copy and assign it like you did above?
    Yes, it's an accepted pattern which you'll see in most of the sample apps. Asnor's code works just as well in this case, and it might always work for you if you stick to that same pattern. However if you were working on a team and everyone else used the more common pattern it might cause a problem. For example, this code would cause a memory leak:
    @property (nonatomic, retain) Click *clicker; // interface
    self.clicker = [[Click alloc] init]; // implementation
    The above is the flip side of your original code. In this case, because we're not releasing the newly alloced object, its retain count is +2 after the setter retains it.
    There are other advantages to the accepted pattern. Suppose you weren't assigning the new object to an ivar but only using the object in that one block of code. Should you then release it? Yes. Will you remember? Well, if you're using the pattern, you'll always release it. If you always release the local pointer regardless of whether it gets retained elsewhere, you're much less likely to have a memory leak. How bout the case where you return the pointer (i.e. alloc an object and return it's address from that method)? In that case you just autorelease it. So whoever called the method needs to retain the returned object if it needs to be used after the current event cycle.
    Either way, immediate release or autorelease, you're always releasing an alloced object in the same block of code.
    Memory management can easily get out of control without following consistent patterns. Alloc->retainBySetter->release is the accepted pattern for Cocoa. Your original code meant to use the correct pattern, but you just forgot that clicker=object isn't the same as self.clicker=object because the latter retains the object. Once you've consistently used the correct pattern for awhile, you'll almost never make that mistake.
    Also, is there any difference in calling it in the following two ways:
    @property (nonatomic, retain) Click *clicker; // <-- must be considered to answer this question
    @synthesize clicker;
    [clicker playClick];
    [self.clicker playClick];
    In the above case there's no difference since the getter synthesized for that property declaration will simply return the value of the ivar (i.e. the address of the retained Clicker object). But in the general case, there certainly could be a difference. If the property was atomic, for example, the results could be different. Of course there will definitely be a difference if you wrote a custom getter that did something more than the default.
    Is there a rule or convention re when to use the getter and when to use the ivar directly? Not that I know of. I think you just need to be aware of what the getter does when deciding whether to use the dot notation. This is a point you might want to research a little more, though. Maybe someone here with more experience in Obj-C or Cocoa will comment.
    In fact a few of the experts in this forum advise against ever using dot notation. They feel it was invented to crash newbie programs. If you never use dot notation the difference between these two lines is much easier to see:
    clicker = newClicker;
    [self setClicker:newClicker];
    But once again, if you stick to the same pattern all the time, it's much harder to make a mistake.
    - Ray

  • Questions about Objects, pointers, and the memory that loves them

    Hey,
    This is all just a theoretical discussion so do understand that the code itself is not germane to the topic.
    I have been mulling over the whole object release/retain/copy thing and need to understand a bit more the real inner workings of the beast. The catalyst for this is the repetitional fervor that most books on the subject of Objective C have employed. Yet they all seem to fail in a complete explanation of the whys and wherefores so that one can determine on her own the correct implementation of this.
    Let's say I have an Object. For the fun of it it is an instance of NSObject and we'll call it myObject.
    When I "create" this object thusly:
    NSObject *myObject = [[NSObject alloc] init];
    What I, in fact get back is a pointer to the object in question, yes?
    So when I "seemingly" add this object to an array like:
    NSArray *myArray = [[NSArray alloc] initWithObject:myObject];
    What is actually placed in the array? is it another pointer to the original object created by myObject or is it a pointer to the pointer of myObject?
    The reason I ask this is because I have run into a situation where some previous instructions on the subject have caused errors. I was told that if I did something like this and then passed the array to a calling method that I could release this array and it would then be the responsibility of the calling method to handle the memory. Further more if I place an object into an array and then copy it into another object of the same type as the original then I could release the array and still have the reference to the first object in the second object. When I have done this I get unpredictable results, sometimes the original object is there and sometimes it isn't
    At what point should I release the array, after it is passed to the calling method (with the use of an autorelease) or when the class that it is encapsulated in is done?
    Sorry about the length of this but I can't believe that I would be the only one that would be helped by such a discussion.
    MM

    etresoft,
    Thanks for the detailed reply. I wish I could say that I wasn't still a bit confused by this. I thought I had this down after going through the lessons. It seems to not be working in practice the way that it works in theory.
    My current project is an example
    In a class I have declared a couple of ivars thusly:
    NSMutableString *source;
    NSMutableString *destination;
    @property (nonatomic, retain) NSMutableString *source;
    @property (nonatomic, retain) NSMutableString *destination;
    This is followed by the appropriate @synthesize directives.
    in the init method for my class I have the following:
    source = [[NSMutableString alloc] initWithString:@"customer"];
    destination = [[NSMutableString alloc] initWithString:@"home"];
    in a method triggered by a button click I have the following:
    if (sender == sourcePop){
    source = [sourcePop titleOfSelectedItem];
    }else{
    destination = [destinationPop titleOfSelectedItem];
    NSLog(@"SOURCE-%@", source);
    NSLog(@"DESTINATION-%@", destination);
    When I run the code and change the source selection the console reads the correct value for what is in the source popupbutton and "home" for the destination. If I then change the destination popupbutton I get a crash and nothing written to the console.
    Placing a breakpoint at the beginning of the "if" and running shows me that just before the crash the source ivar is reported as "out of scope." There are no release or autorelease statements for this ivar anywhere in the class. Yet if I change the line that sets the ivar to the value of the popupbutton to this:
    [source = [sourcePop titleOfSelectedItem] retain];
    The debugger will have the correct value for the ivar and when run normally there is no crash.
    I would assume that the problem is that the ivar is being released but I am not the one releasing it. Why does this behavior happen? Shouldn't the retain count still be 1 since the @property directive has it and there is no release in the code? Or is it that the statement that sets the ivar to the value of the popup really just setting it to the pointer and it is the popup that is somehow being released?
    Is there something else that I should be doing?
    MM

  • A question about objects and queries

    I just started using COM objects in ColdFusion. I am mostly
    using CreateObject, but occasionaly use <CFOBJECT>
    My question is; Do I have to destroy these object variables
    when I am done? I know in a lot of other languages I work in, you
    have to "clean up'" after yourself and destroy some variables when
    you are done to avoid memory leaks. How does CF handle this?
    While I am asking, what about queries? Do hey have to be
    destroyed as well? What about queries made with QueryNew?
    Thank you for the help.

    Cold fusion cleans up for you.
    You do not need to explicitly destroy anything unless threads
    are spawned in a non standard way by Java or C code that you are
    using.

  • Question about multiple classes and Linked Lists

    Lets say you have 4 classes: LinkedList which is the main class, Node, Card, and Hand. im not putting any constructors yet
    The card class keeps track of a card such as a king of diamonds:
    public class Card {
    string suit;
    string rank;
    the node class has a Card object and another node object so it would be
    public class Node {
    Card c;
    Node next;
    the hand class keeps track of the users hand. This program will ask the user if they want to add, remove, print out the hand, or print out the score of the hand, I guess it would be like this
    public class Hand {
    Node head;
    The linkedlist class will contain all the methods for doing the above
    now my questions are. Lets say I want to add a card, so I would have to add a new Node which contains the card. If i wanted to access the new nodes card contents, lets call this node g, can i do, g.c.suit and g.c.rank in which this case c is the card object in Node. Also, these are not going to be nested classes, they are going to be 4 seperate classes, if I declare all variables as private will I need to extend the classes or not and if there is a better way, let me know. Thanks alot for all your help and previous help.

    here is an example of Card and Hand ...
    not saying its good design
    but it does work
    public class Cards {
    public static void main(String[ ] args) {
    Card c1 = new Card ("ace", "diamonds");
    Card c2 = new Card ("two", "spades");
    Card c3 = new Card ("three", "hearts");
    Hand a1 = new Hand ();
    a1.add(c1);
    a1.add(c2);
    a1.add(c3);
    System.out.println("\nshowing hand ...");
    a1.show();
    System.out.println("\ndeleting " + c2.num + " " + c2.suite);
    a1.del(c2);
    System.out.println("\nshowing hand ...");
    a1.show();
    } // main
    } // class
    class Hand exists in 3 states
    and is designed to be a chain of cards ...
    1. when class Hand is first created
       a. it has no card
       b. and no nextHand link
    2. when somecard is added to this Hand
       a. it has a card
       b. and the nextHand link is null
    3. when somecard is attempted to be added to this Hand
       and it already has a card
       then a nextHand is created
       and the somecard is added to the nextHand
       a. so the Hand has a card
       b. and the Hand has a nextHand
    class Hand {
    public Card acard;
    public Hand nextHand;
    public Hand () {
      acard = null;
      nextHand = null;
    public void add (Card somecard) {
      if (acard == null) {
        acard = somecard;
        return;
      if (nextHand == null) nextHand = new Hand();
      nextHand.add (somecard);
    delete this Hand by making this Hand
    refer to the next Hand
    thus skipping over this Hand in the nextHand chain
    for example, removing Hand 3 ...
    1  -  2  -  3  -  4   becomes
    1  -  2  -  4
    public void del (Card somecard) {
      if (acard == somecard) {
        if (nextHand != null) acard = nextHand.acard;
        else acard = null;
        if (nextHand != null) nextHand = nextHand.nextHand;
        return;
      nextHand.del(somecard);
    public void show() {
      if (acard == null) return;
      System.out.println(acard.num + " " + acard.suite);
      if (nextHand != null) nextHand.show ();
    } // class
    class Card {
    public String num;
    public String suite;
    Card (String num, String suite) {
      this.num = num;
      this.suite = suite;
    } // class

  • Question about multiple class files

    I just started learning JAVA a couple of days ago and the first program I wrote had two classes in one file. here is the program :
    class fib_num {
    public int value;
    public boolean is_even;
    class Fibonacci {
    /** Print the Fibonacci sequence for values < MAX and mark even numbers with an asterick */
    private static final int MAX = 50;
    private static final String Title = "The Fibonacci sequence for values less than " + MAX + ":";
    private static fib_num[] fib = new fib_num[MAX];//This is actually an array of object
    //references to objects of the fib_num class
    public static void main(String[] args) {
    System.out.println(Title);
    //We must initialize each element of the array also !!!!
    for (int i = 0; i < fib.length; i += 1) {
    fib = new fib_num();
    int lo = 1, hi = 1;
    fib[0].value = lo;
    fib[0].is_even = false;
    fib[1].value = hi;
    fib[1].is_even = false;
    for (int i = 2; i < fib.length; i += 1) {
    //create the next Fibonacci number and then save the previous Fibonacci number
    hi = lo + hi;
    lo = hi - lo;
    fib.value = hi;
    //now indicate if the Fibonacci number is even/odd
    if (fib.value % 2 == 0) {
    fib.is_even = true;
    }else {
    fib.is_even = false;
    print (fib);
    //This method prints an array of Fibonacci numbers
    public static void print(fib_num[] array) {
    if (array == null || array.length == 0)
    throw new IllegalArgumentException();
    String mark;
    for (int i = 0; array.value < MAX; i += 1) {
    if (array.is_even) {
    mark = "*";
    }else {
    mark = "";
    System.out.println((i + 1) + ": " + array.value + mark);
    I ran the program and everything went fine. But today I started to write another program with two classes. However the file will not compile and I get an error about interfacing or something. here is the program:
    Note: it's not nearly complete.
    class enumerate {
    //print out all permutations of a list of integers
    public static final int MAX = 4;
    public static int[] initialize(int[] nums) {
    for (int i = 0; i < nums.length; i++) {
    nums = i + 1;
    return nums;
    public static void print(int[] nums) {
    for (int i = 0; i < nums.length; i++) {
    System.out.print(nums);
    System.out.println("");
    public static void swap (int[] nums, int i, int j) {
    int temp = nums;
    nums = nums[j];
    nums[j] = temp;
    public static void main (String[] args) {
    int[] list = new int[MAX];
    list = initialize(list);
    PermutationGenerator x = new PermutationGenerator(5);
    // Systematically generate permutations.
    import java.math.BigInteger;
    public class PermutationGenerator {
    private int[] a;
    private BigInteger numLeft;
    private BigInteger total;
    // Constructor. WARNING: Don't make n too large.
    // Recall that the number of permutations is n!
    // which can be very large, even when n is as small as 20 --
    // 20! = 2,432,902,008,176,640,000 and
    // 21! is too big to fit into a Java long, which is
    // why we use BigInteger instead.
    public PermutationGenerator (int n) {
    if (n < 1) {
    throw new IllegalArgumentException ("Min 1");
    a = new int[n];
    total = getFactorial (n);
    reset ();
    // Reset
    public void reset () {
    for (int i = 0; i < a.length; i++) {
    a = i;
    numLeft = new BigInteger (total.toString ());
    // Return number of permutations not yet generated
    public BigInteger getNumLeft () {
    return numLeft;
    // Return total number of permutations
    public BigInteger getTotal () {
    return total;
    // Are there more permutations?
    public boolean hasMore () {
    return numLeft.compareTo (BigInteger.ZERO) == 1;
    // Compute factorial
    private static BigInteger getFactorial (int n) {
    BigInteger fact = BigInteger.ONE;
    for (int i = n; i > 1; i--) {
    fact = fact.multiply (new BigInteger (Integer.toString (i)));
    return fact;
    // Generate next permutation (algorithm from Rosen p. 284)
    public int[] getNext () {
    if (numLeft.equals (total)) {
    numLeft = numLeft.subtract (BigInteger.ONE);
    return a;
    int temp;
    // Find largest index j with a[j] < a[j+1]
    int j = a.length - 2;
    while (a[j] > a[j+1]) {
    j--;
    // Find index k such that a[k] is smallest integer
    // greater than a[j] to the right of a[j]
    int k = a.length - 1;
    while (a[j] > a[k]) {
    k--;
    // Interchange a[j] and a[k]
    temp = a[k];
    a[k] = a[j];
    a[j] = temp;
    // Put tail end of permutation after jth position in increasing order
    int r = a.length - 1;
    int s = j + 1;
    while (r > s) {
    temp = a[s];
    a[s] = a[r];
    a[r] = temp;
    r--;
    s++;
    numLeft = numLeft.subtract (BigInteger.ONE);
    return a;
    I thought the error had somethin to do with only having one class per .java file since the compiler creates a .class file. But how come my first program had two classes and it was OK. Is it b/c the second class was merely a collection of fields, almost like a simple struct in C?
    Any help would be appreciated. Thanks

    Move the import java.math.BigInteger line to the start of the file.
    Use the "[ code ] [ /code ]" tags around your code when you post, it makes reading it a lot easier.

  • Question about PickMouseBehavior class

    Hello, I wrote yesterday in this forum, but now my problem is other. I'm doing a extension of PickMouseBehavior class, but I want that these class is only activated with a specific mouse button or when I passing the mouse over determinated Box element(Box is my branchgroup for the PickMouseBehavior class).
    How can I do it?? I think that I have to redefine the initialize and processStimulus methods, but I don't know how can I do it. Anybody can help me please??
    Sorry about my bad english.
    Thanks

    i think is in the Class class. I'm not so sure as don't have the API on this machine. You can get the class from every object from the getClass() method, then call the getResource() or getResourceAsStream() i can't really remember...

  • Javascript question about objects

    Hi,
    Let's say I've created a new object. One of the properties of my object
    is an array. I would like another property to return the length of that
    array. How do I do this.
    For instance here's some code (and I hope that the email interface
    doesn't screw this up so badly to make it unreadable. I'm going to avoid
    using square brackets as well by using round ones instead even though
    it's a syntax error, since square ones are known not to work with email.)
    function test(){
         this.a = new Array();
         this.b = this.a.length;
    x = new test();
    x.a(0) = 3;
    x.a(1) = 3;
    x.b;
    Returns 0. In other words, just setting this.b = this.a.length doesn't
    not get updated automatically as this.a is added to.
    Now, I tried turning this.b into a method (ie this.b = function(){return
    this.a.length)  and that works, but then to get the length I keep having
    to refer to myObject.b().
    How can I avoid that? How can I have a built-in length property for an
    object.
    Hope this is clear and has come out legibly via email. Apologies in
    advance if it hasn't.
    Thanks,
    Ariel

    Hi all,
    1) About the original question—which doesn't regard prototype inheritance in itself: "How can I have a built-in length property for an object"—I think the most obvious approach is to directly use an Array as the base object. Since any Array is an Object you can append methods and properties to it while keeping benefit from the whole array's API:
    var myData = [];
    myData.myProp = 'foo';
    myData.myMeth = function(){ return [this.myProp, this.length, this.join('|')]; };
    // Usage
    myData[0] = 10;
    myData[1] = 20;
    alert( myData.myMeth() ); // => foo,2,10|20
    // etc.
    2) Now, if for whatever reason you cannot use the previous technique or need to deal with a precustomized Object structure such as:
    var myObj = {
        items: [],
        meth: function(){ alert("Hello World!"); },
        // etc.
    then the challenge is more difficult for the reasons that Jeff mentioned above. You can anyway mimic a kind of 'binding' mechanism this way:
    // The original obj
    var myObj = {
        items: [],
        meth: function(){ alert("Hello World!"); }
    // Adding length as a 'fake property' (getter and setter)
    (myObj.length = function F(n)
        if( !F.root )
            (F.root=this).watch('length', function(_,ov,nv){ F(nv); return ov; });
            F.valueOf = function(){ return F().valueOf(); };
            F.toString = function(){ return F().toString(); };
        if( 'undefined' == typeof n )
            n = F.root.items.length >>> 0;
        else
            F.root.items.length = n;
        return n;
    }).call(myObj);
    // Usage
    myObj.meth(); // => Hello World!
    myObj.items[0] = 10;
    myObj.items[1] = 20;
    alert( myObj.length ); // => 2
    var x = myObj.length-1; // works too, thanks to F.valueOf
    alert( x ); // => 1
    myObj.length = 5; // testing the setter
    alert( myObj.length ); // => 5
    alert( myObj.items ); // => 10,20,,,
    Of course it's totally unreasonable to implement such an artillery just for the convenience of writing myObj.length instead of myObj.length()—and myObj.length=x instead of myObj.length(x)—so I only suggest this for the sake of experimentation.
    @+
    Marc

  • Question about Math Class

    I have a couple of Java questions I was wondering if anyone could answer:
    1). In this one statement, which takes the greatest common denominator and places it in the variable commom:
    int common = gcd (Math.abs(numerator), denominator);
    A).What is gcd? I looked it up and it's not a reserved word in the math class. In the class that this statement comes from there is no variable, object, or method named gcd. There is also no gcd variable, object, or invoked method in the client code that uses the class that this statement comes from.
    B ). I know that abs is a method of the math class for the absolute value of a number(in this case the number inside the variable numerator.). And I know that when the abs method is invoked it sends the variable 'numerator' as the parameter for the data to take the absolute value of. What I don't understand is the syntax of this statement in regards to how you can take the absolute value of the variable 'denominator' haveing a variable 'numerator' inclosed in the parenthesis and simpley adding a comma to include the variable 'denominator' in the argument to be sent in the invocation of the abs method. It seems like this would be the correct syntax:
    int common = (Math.abs(numerator))/(Math.abs(denominator));
    Can anyone explain the 'int common = gcd (Math.abs(numerator), denominator);'
    statement?
    Thanks,
    -dman

    > A).What is gcd?
    As already been said: it's the Greatest Common Divider.
    Example: fraction 9/24, then gcd(9, 24) == 3.
    >It seems like this would be the correct syntax:
    int common = (Math.abs(numerator))/(Math.abs(denominator));
    Probably the gcd(...) method is used to normalize a fraction whose denominator is always positive. If the fraction is smaller then zero, the numerator is negative. And to caculate the Greatest Common Divider of two numbers, the gcd(...) method needs two positive arguments.
    Google for "Euclid GCD algorithm".

  • Question about objects

    Hi
    I make a number of objects, they are all from the same class but have differing values.
    I put the objects into different arrays
    I put all the objects in a hash table so that i can associate the object with a string.
    tempOb = create.make()
    compFd= tempOb; //
    tempStr = compFd[i].returnTextValue();
    theRef.put(tempStr, tempCard);
    My question is where do the objects actually exist - and where are they only a reference to the object ? I ask because i am thinking that maybe its uneccsary to make arrays for objects when i could simply have string arrays and use the string to take the object from the hash table.
    Thanks

    Hi
    I make a number of objects, they are all from the same
    class but have differing values.
    I put the objects into different arrays
    I put all the objects in a hash table so that i can
    associate the object with a string.
    tempOb = create.make()
    compFd= tempOb; //
    tempStr = compFd[i].returnTextValue();
    theRef.put(tempStr, tempCard);
    My question is where do the objects actually exist -
    and where are they only a reference to the object ? I
    ask because i am thinking that maybe its uneccsary to
    make arrays for objects when i could simply have
    string arrays and use the string to take the object
    from the hash table.
    Thanks
    FIrst of all you need to revisit what an object is?
    An object is a self-contained entity which has its own private collection of properties (ie data) and methods (ie. operations) that encapsulate functionality into a reusable and dynamically loaded structure. After a class definition has been created as a prototype, it can be used as a template for creating new classes that add functionality. Objects are programing units of a particular class. Dynamic loading implies that applications can request new objects of a particular class to be supplied on an 'as needed' basis. Objects provide the extremely useful benefit of reusable code that minimizes development time. As far as the storage is concerned and all object variables are references.

  • Question about Object Oriented Design in Oracle

    Hi everyone,
    Right now I'm updating my oracle skills, years ago without programming (last time with Oracle 7.3 :O)
    Well, if I have to design a new system with this features:
    1.- Using Oracle as DB
    2.- Web enable
    3.- OO Design
    My questions:
    1.- What is the best practice to make database design? E-R + Object Types? I mean is better making the design on Oracle directly or in Java-UML environment?
    2.- I was thinking in programming with Forms, but it works well with OO design?
    3.- If I want to program some web services based, Could I do it with PL/SQL and Jdeveloper?
    please if you know about articles and whitepapers about OO design approach with Oracle let me know!
    Thanks.

    I have been involved in some of these projects that have used Java, C#, VB, C++ etc. as front-end languagaes. I have been able to implement these projects successfully using the following approach:
    1. create a relational model of the database - third-normal form (assuming it is an OLTP application)
    2. Write PL/SQL code (packages and procedures mainly)
    3. Interact with the front-end layer by sending and receiving ref curosors and/or PL/SQL tables
    If you want to use Forms (I am assuming Oracle Forms) then there may not be much need for an OO design. Embeeding SQL in the forms will do most of what you want.
    Shakti
    http://www.impact-sol.com
    Developers of Guggi Oracle - Tool for DBAs and Developers

  • A question about calling classes

    Hi,
    I have a question regarding software design so that each class is independent of other.
    public class A
        public void methodA()
                 B m_B=new B();
              String strA=m_B.getBString();
              System.out.println(strA);
    public class B
       public String getBString()
                      return "someString";
    }My question: Is it possible to call the method in class B from class A without creating an instance of class B in method of class A ?
    I am trying to figure out if this can be done using interfaces and abstract classes.
    I am waiting for some suggestions and if you have completely different suggestion then I am open for it too.
    thanks in advance,
    @debug.

    interface I {
        String getString();
    class B implements I {
        public String getString() { return "someString";}
    class A {
        private I foo;
        public void setFoo(I foo) {this.foo = foo;}
        public I getFoo() {return foo;}
        public void methodA() {
          System.out.println(getFoo().getString());
    public class Main {
        public static void main(String[] args) {
            A a = new A();
            a.setFoo(new B());
            a.methodA();
    }There's one problem with decoupling A and B in this case - A's method creates an instance of B. The above is one solution. There are many others.

Maybe you are looking for