Re: script object properties: seeking confirmation
Re: script object properties: seeking confirmation
- Subject: Re: script object properties: seeking confirmation
- From: has <email@hidden>
- Date: Tue, 5 Mar 2002 13:04:51 +0000
Bill Hoffman wrote:
>
I can't dynamically create a new property of an object at
>
runtime in this manner (like I could in JavaScript, for example, with
>
"this.income = 500;")
>
>
If there's a way to do that I'd love to know how, but I'm pretty sure
>
there isn't.
Don't think so. I'm curious though why you'd want to avoid declaring your
object's properties at compile time.
A couple of reasons I could think of for doing this might be:
1. if you've got a bunch of old objects already in existence that you want
to retroactively add new properties/methods to. The only solution I can
think of there would be to go through all these old objects, migrating
their date to your new-and-improved objects.
2. if you want to trap runtime errors caused by the user trying to get a
value before it's been defined. [i.e. "If the user tries to get 'income'
before it's been set, trap the error and warn the user that they haven't
input a value for 'income' yet."] This could be addressed by having the
user access the object's internal state via methods, rather than by
manipulating its properties directly.
script obj
property val : missing value
--
on getVal()
if val is missing value then error "Value undefined."
val
end getVal
--
on setVal(newVal)
set val to newVal
end setVal
end script
But that's just me popping random ideas off the top of my head. Maybe if
you could give more details of the problem you're trying to solve?
Cheers,
has
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.