Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Equivalent to window
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  11 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Matt Mower  
View profile  
 More options Sep 30 2009, 6:15 pm
From: Matt Mower <s...@mattmower.com>
Date: Wed, 30 Sep 2009 23:15:58 +0100
Local: Wed, Sep 30 2009 6:15 pm
Subject: Equivalent to window
Hi.

Just coming back to using JSCocoa after some time and, of course, all
knowledge has evaporated.

I'm looking to provide some jQuery style functions for scripting my
app which I want to be globally available. Taking a look at the jQuery
source code I notice they are using 'window' as a global context for
the browser session.

Is there an equivalent global context object in JSCocoa to which I can
attach functions such as '$' ?

Thanks,

Matt

--
Matt Mower :: http://mattmower.com/


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Patrick Geiller  
View profile  
 More options Sep 30 2009, 7:03 pm
From: Patrick Geiller <parman...@gmail.com>
Date: Thu, 1 Oct 2009 01:03:04 +0200
Local: Wed, Sep 30 2009 7:03 pm
Subject: Re: Equivalent to window

Hi Matt !

Just use 'this' in the global scope. In a webpage's global scope,  
'this' and 'window' are two different names for the global object  
(alert(this==window) will return true)

JSCocoa has no default name for the global object, you can create one  
yourself :

        var globalObject = this

        function attachStuffToGlobalObject()
        {
                globalObject.$ = function () { ... }
        }
        // Add stuff
        attachStuffToGlobalObject()
        // Call added stuff
        $(....)

'$' will then be globally available.

-Patrick


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Matt Mower  
View profile  
 More options Sep 30 2009, 7:32 pm
From: Matt Mower <s...@mattmower.com>
Date: Thu, 1 Oct 2009 00:32:13 +0100
Local: Wed, Sep 30 2009 7:32 pm
Subject: Re: Equivalent to window

On Thu, Oct 1, 2009 at 12:03 AM, Patrick Geiller <parman...@gmail.com> wrote:
> Just use 'this' in the global scope. In a webpage's global scope, 'this' and
> 'window' are two different names for the global object (alert(this==window)
> will return true)

Ah, sweet. Thanks Patrick.

Are you aware of any components/frameworks for syntax aware JS editing
that I could embed?

I'm also interested in what kind of debugging support might be
available, any thoughts about that?

Matt

--
Matt Mower :: http://mattmower.com/


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Matt Mower  
View profile  
 More options Sep 30 2009, 8:08 pm
From: Matt Mower <s...@mattmower.com>
Date: Thu, 1 Oct 2009 01:08:40 +0100
Local: Wed, Sep 30 2009 8:08 pm
Subject: Re: Equivalent to window
Hi Patrick.

On Thu, Oct 1, 2009 at 12:03 AM, Patrick Geiller <parman...@gmail.com> wrote:
> Just use 'this' in the global scope. In a webpage's global scope, 'this' and
> 'window' are two different names for the global object (alert(this==window)
> will return true)

I've just realised this isn't quite what i want. In a browser each
window provides it's own global context. In my app I have one JSCocoa
sharedController instance but that is creating a global context over a
range of "documents".

This means that my $ function can't make inferences about where to
look for certain things.

It occurs to me that I might be able to do this by creating a scope
for each document within which the $ function is defined related to
that scope. I guess I would then need to use bind to call my
Javascript callback function in the context of the appropriate scope
object.

Looking at my use of callJSFunction it's not clear to me how I'd use
bind to set the scope of the function call.

Does what I'm saying (even broadly) make sense? And, if so, do you
have any advice about how I can implement this?

Thanks,

Matt

--
Matt Mower :: http://mattmower.com/


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ian Beck  
View profile  
 More options Sep 30 2009, 8:32 pm
From: Ian Beck <georgethef...@gmail.com>
Date: Wed, 30 Sep 2009 17:32:04 -0700
Local: Wed, Sep 30 2009 8:32 pm
Subject: Re: Equivalent to window
Hey Matt,

Not sure if this is really applicable to your scenario, but for my  
Spice plugin for Espresso, I use a Javascript wrapper to load in  
individual plugin files that makes handling scope a lot easier.  
Basically, the Objective-C code loads up my bootstrapping function  
using callJSFunctionNamed:withArguments: and passes specific data  
about the current context via the arguments. The bootstrapping  
function then configures standard global variables, loads the plugin  
file into a generic function to keep it in its own scope, and then  
executes the main function of the plugin file (if there is one).  You  
could presumably do something similar, using the bootstrapping  
function to configure the specific scope variables that need to be  
available to your plugins.  The whole process was inspired by Narwhal  
and its Server.js modular approach to handling Javascript, and the  
benefit would be that you could then use things like binding and so  
forth a lot easier than trying to do it straight from Objective-C.

For reference, here's the specific line where I'm loading in the  
plugin file to a generic function (SpiceController is a globally  
available object I setup with JSCocoa so I could make use of file I/O  
and so forth):

http://github.com/onecrayon/Spice-sugar/blob/master/Support/Library/b...

The rest of the bootstrapping file is probably too specific to my  
project to be much use to you, but hopefully that'll give you some  
idea of what the heck I'm talking about.  :-)

Good luck!  I'd be interested to hear if you come up with an  
alternative for handling scope in JSCocoa-loaded Javascript plugins.

Ian

On Sep 30, 2009, at 5:08 PM, Matt Mower wrote:


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Gus Mueller  
View profile  
 More options Sep 30 2009, 9:02 pm
From: Gus Mueller <g...@flyingmeat.com>
Date: Wed, 30 Sep 2009 18:02:16 -0700
Local: Wed, Sep 30 2009 9:02 pm
Subject: Re: Equivalent to window
On Sep 30, 2009, at 4:32 PM, Matt Mower wrote:

> Are you aware of any components/frameworks for syntax aware JS editing
> that I could embed?

Feel free to lift the stuff from JSTalk:
http://github.com/ccgus/jstalk

It's got a little editor which does the syntax coloring.  Let me know  
if you make any improvements :)

-gus

--  

August 'Gus' Mueller
Flying Meat Inc.
http://flyingmeat.com/


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Matt Mower  
View profile  
 More options Oct 1 2009, 3:54 am
From: Matt Mower <s...@mattmower.com>
Date: Thu, 1 Oct 2009 08:54:14 +0100
Local: Thurs, Oct 1 2009 3:54 am
Subject: Re: Equivalent to window

On Thu, Oct 1, 2009 at 2:02 AM, Gus Mueller <g...@flyingmeat.com> wrote:
> Feel free to lift the stuff from JSTalk:
> http://github.com/ccgus/jstalk

> It's got a little editor which does the syntax coloring.  Let me know
> if you make any improvements :)

Awesome Gus, thank you.

Matt.

--
Matt Mower :: http://mattmower.com/


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Matt Mower  
View profile  
 More options Oct 1 2009, 6:20 am
From: Matt Mower <s...@mattmower.com>
Date: Thu, 1 Oct 2009 11:20:56 +0100
Local: Thurs, Oct 1 2009 6:20 am
Subject: Re: Equivalent to window
Hi Ian.

On Thu, Oct 1, 2009 at 1:32 AM, Ian Beck <georgethef...@gmail.com> wrote:
> Not sure if this is really applicable to your scenario, but for my
> Spice plugin for Espresso, I use a Javascript wrapper to load in
> individual plugin files that makes handling scope a lot easier.
> Basically, the Objective-C code loads up my bootstrapping function
> using callJSFunctionNamed:withArguments: and passes specific data
> about the current context via the arguments. The bootstrapping
> function then configures standard global variables, loads the plugin
> file into a generic function to keep it in its own scope, and then
> executes the main function of the plugin file (if there is one).  You

I've been thinking it over and I'm concerned that my app is also
multi-document and there is threading involved.

I can't remember now whether JSCocoa supports access from multiple
threads. I recall when I was using MacRuby I had to switch all my
callbacks to the main thread due to crash issues there... not sure if
I switched things back.

It occurs to me that the safest approach might be to use a separate
JSCocoa instance for each document which will also solve the scope
issue.

Alternatively I could rip out multi-document which hasn't turned out
to be very useful in this app.

Thanks for the suggestions. I have some puzzling to do :)

m.

--
Matt Mower :: http://mattmower.com/


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Patrick Geiller  
View profile  
 More options Oct 1 2009, 8:25 am
From: Patrick Geiller <parman...@gmail.com>
Date: Thu, 1 Oct 2009 14:25:28 +0200
Local: Thurs, Oct 1 2009 8:25 am
Subject: Re: Equivalent to window

Hi Matt,

* Regarding the scope from multiple instances : do you need to worry  
about that ? Why not create your '$' function in each one of your  
documents ?

* Threading : JSCocoa isn't thread safe. I don't think it'd crash, but  
you might get errors of undefined objects. I need to fix this.

* Sharing js stuff between multiple contexts : starting from Safari 4,  
there is the concept of concept groups which I think I must use (use  
JSGlobalContextCreateInGroup for each dependant context, in your case  
each document context). But then I don't remember what data you need  
to share data across contexts ? Maybe Ian's method would be the  
simplest ? Have one context, with each document having its own scope.

-Patrick


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Matt Mower  
View profile  
 More options Oct 1 2009, 8:54 am
From: Matt Mower <s...@mattmower.com>
Date: Thu, 1 Oct 2009 13:54:42 +0100
Local: Thurs, Oct 1 2009 8:54 am
Subject: Re: Equivalent to window

On Thu, Oct 1, 2009 at 1:25 PM, Patrick Geiller <parman...@gmail.com> wrote:
> * Regarding the scope from multiple instances : do you need to worry
> about that ? Why not create your '$' function in each one of your
> documents ?

Thanks for clarifying these issues Patrick.

But in order for the function to be globally available it needs to be
attached to the global object, no? If I put it in the document then I
will have to reference it via a document instance which is certainly
possible but less succinct. Or am I missing something?

I confess my JS knowledge is rather pedestrian.

> * Threading : JSCocoa isn't thread safe. I don't think it'd crash, but
> you might get errors of undefined objects. I need to fix this.

Okay. I suspect I probably didn't go back to multi-threading since
I've not had any crashes. However I've not made much use of it either
because it hasn't turned out to be as convenient as I'd hoped.

That's largely because any errors in the script aren't easily managed
from within the app.

> * Sharing js stuff between multiple contexts : starting from Safari 4,
> there is the concept of concept groups which I think I must use (use
> JSGlobalContextCreateInGroup for each dependant context, in your case
> each document context). But then I don't remember what data you need
> to share data across contexts ? Maybe Ian's method would be the
> simplest ? Have one context, with each document having its own scope.

Actually it's the reverse I don't want to share anything between
documents, I want - essentially - the browser case of each document
being entirely independent.

I'm actually thinking about dumping multiple documents altogether.
When I started building Elysium I made it multi-document because my
previous two apps I hadn't and I ended up regretting it and having to
retrofit it.

But multi-document has never, in practice, made much sense in Elysium.
It might considerably simplify things to get rid of it. But it would
be quite a wrench code wise.

I want to take a look at Gus' code this evening and try and steal his
editor (at the moment I use a plain text view). I'd also like to have
some smarter error trapping and debugging facility. Not sure what's
possible there.

Still I now actually need this in earnest so it's time to knuckle down
and figure it all out.

Thanks again.

Matt

--
Matt Mower :: http://mattmower.com/


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Patrick Geiller  
View profile  
 More options Oct 1 2009, 10:55 am
From: Patrick Geiller <parman...@gmail.com>
Date: Thu, 1 Oct 2009 16:55:30 +0200
Local: Thurs, Oct 1 2009 10:55 am
Subject: Re: Equivalent to window

> But in order for the function to be globally available it needs to be
> attached to the global object, no? If I put it in the document then I
> will have to reference it via a document instance which is certainly
> possible but less succinct. Or am I missing something?

I meant if you give document its own JSCocoa instance, you can just  
load the same '$' function in each. (Just call evalJSFile('$.js') on  
each)

> Okay. I suspect I probably didn't go back to multi-threading since
> I've not had any crashes. However I've not made much use of it either
> because it hasn't turned out to be as convenient as I'd hoped.

> That's largely because any errors in the script aren't easily managed
> from within the app.

Yes, handling script errors can be a pain, all the more if it's  
multithreaded. And right now, don't use multithreading in JSCocoa.

> Actually it's the reverse I don't want to share anything between
> documents, I want - essentially - the browser case of each document
> being entirely independent.

OK, then no problem. Just use a different JSCocoa instance for each  
document. This way you don't have to worry about sharing stuff, each  
one is independant and has its own global object and data.

> But multi-document has never, in practice, made much sense in Elysium.
> It might considerably simplify things to get rid of it. But it would
> be quite a wrench code wise.

Be careful to not regret it again ! Given that you're building a music  
synthesizer, having two documents open - like a tutorial document and  
the document you're working on - can be very useful. You should keep  
documents around.

> I want to take a look at Gus' code this evening and try and steal his
> editor (at the moment I use a plain text view). I'd also like to have
> some smarter error trapping and debugging facility. Not sure what's
> possible there.

Ok ! Also check out Gus' error handling code : (via a delegate method)
http://github.com/ccgus/jstalk/blob/master/src/JSTDocument.m#L187

Right now there's no debugging support, but you can have the line and  
description of last error.

-Patrick


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2010 Google