Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > how to eval in the global scope

Reply
Thread Tools

how to eval in the global scope

 
 
a.farhadi@gmail.com
Guest
Posts: n/a
 
      10-27-2005
hi guys,

I want to eval some javascript code at a function. and my code contains
some variable and function definitions.

my problem is that the code is evaluated in function scope not global
scope and definations are not available in the global scope.

 
Reply With Quote
 
 
 
 
Randy Webb
Guest
Posts: n/a
 
      10-27-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) said the following on 10/26/2005 11:07 PM:
> hi guys,
>
> I want to eval some javascript code at a function. and my code contains
> some variable and function definitions.


Why do you think you need eval?

> my problem is that the code is evaluated in function scope not global
> scope and definations are not available in the global scope.


Then make them global in scope.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
 
Reply With Quote
 
 
 
 
Farhadi
Guest
Posts: n/a
 
      10-27-2005
I load some js code on runtime using XMLHTTPRequest.
but I cant run it on the global scope.

Is there any more ways except eval?

 
Reply With Quote
 
Farhadi
Guest
Posts: n/a
 
      10-27-2005

Randy Webb wrote:
> > I load some js code on runtime using XMLHTTPRequest.
> > but I cant run it on the global scope.
> > Is there any more ways except eval?

>
> That depends on the code itself actually.
>
> Have the code generated in a manner that it can be appended in a script
> block, wrapped in a function, and then the function called. But that
> depends on the code and what it is supposed to do.
>
> There also may be a better way than an XMLHTTPRequest.





before, I had included my js files thruogh Script block at the HEAD.

now I want to include them using XMLHTTPRequest because of 2 reason:
1. I want to load scripts on onload event of body. to speed up loading
of page.
2. I dont want my scripts be saveable thruogh "Save As" at browser.

and I want to run my script just like including them on a script block.
is there any more ways?

 
Reply With Quote
 
RobG
Guest
Posts: n/a
 
      10-27-2005
Farhadi wrote:
> Randy Webb wrote:
> > > I load some js code on runtime using XMLHTTPRequest.
> > > but I cant run it on the global scope.
> > > Is there any more ways except eval?

> >
> > That depends on the code itself actually.
> >
> > Have the code generated in a manner that it can be appended in a script
> > block, wrapped in a function, and then the function called. But that
> > depends on the code and what it is supposed to do.
> >
> > There also may be a better way than an XMLHTTPRequest.

>
>
>
>
> before, I had included my js files thruogh Script block at the HEAD.
>
> now I want to include them using XMLHTTPRequest because of 2 reason:
> 1. I want to load scripts on onload event of body. to speed up loading
> of page.


Then use an onload event to load the scripts by adding script elements
with src attributes that link the files.

But your intention seems misguided, unless the scripts are really huge
(by script standards, say more than 50KB) then they will have little or
no effect on the time taken to load the page (assuming a non-trivial
site).


> 2. I dont want my scripts be saveable thruogh "Save As" at browser.


Presuming XMLHttpRequest will prevent that (and even if it does, how
long will it last?) what is the point? It will not prevent
knowledgeable users from creating their own local copies of your script
files should they wish.

If your scripts are worth copying, anyone defeated by XMLHttpRequest or
other means will likely not have a use for them anyway. Those who know
how to get around your defences will - your scripts will be in the
hands of those who may (if my guessing of your thoughts is correct)
best benefit from them.

In my experience such users find it easier and faster to write their
own scripts, particularly if they are to be used on a site with any
kind of quality control system.

>
> and I want to run my script just like including them on a script block.
> is there any more ways?


Then do that. There are utilities to minify code, some of which result
in sufficient obfuscation that the effort required to de-mystify the
code makes it not worth while (though I would never suggest that as a
sole criterion for minification, it may be considered a useful
side-effect by some).

<URL:http://www.crockford.com/javascript/jsmin.html>


--
Rob

 
Reply With Quote
 
Julian Turner
Guest
Posts: n/a
 
      10-27-2005

RobG wrote:

> > 2. I dont want my scripts be saveable thruogh "Save As" at browser.

>
> Presuming XMLHttpRequest will prevent that (and even if it does, how
> long will it last?) what is the point? It will not prevent
> knowledgeable users from creating their own local copies of your script
> files should they wish.


I agree. HTTPRequest certainly won't protect against this, as you can
use another HTTPRequest in the address bar to get the script quite
easily.

E.g.:

javascript: var sURL="http://www.somewebsite.com/myscript.js"; var
oRequest=new ActiveXObject("Msxml2.XMLHTTP"); oRequest.open("GET",
sURL,false); oRequest.send(null); alert(oRequest.responseText);

>There are utilities to minify code


This is another one to consider, for compression purposes.

http://dean.edwards.name/packer/

Julian

 
Reply With Quote
 
Joshie Surber
Guest
Posts: n/a
 
      10-27-2005
> but I cant run it on the global scope.

remove the "var" declorations before the variable names and they will
be global, just make sure they don't conflict with another variable
with the same name.

> Please quote what you are replying to.
>
> If you want to post a followup via groups.google.com, don't use the
> "Reply" link at the bottom of the article. Click on "show options" at
> the top of the article, then click on the "Reply" at the bottom of the
> article headers.


Lose the canned message text. If it were important to people other than
you it would be in the FAQ.

 
Reply With Quote
 
Randy Webb
Guest
Posts: n/a
 
      10-27-2005
Joshie Surber said the following on 10/27/2005 4:44 AM:
>>but I cant run it on the global scope.

>
>
> remove the "var" declorations before the variable names and they will
> be global, just make sure they don't conflict with another variable
> with the same name.
>
>
>>Please quote what you are replying to.
>>
>>If you want to post a followup via groups.google.com, don't use the
>>"Reply" link at the bottom of the article. Click on "show options" at
>>the top of the article, then click on the "Reply" at the bottom of the
>>article headers.

>
>
> Lose the canned message text. If it were important to people other than
> you it would be in the FAQ.


With a response like that, it becomes obvious that you have not read the
FAQ that you say it would be in because it *is* in the FAQ. Since you
can not seem to find it or want to find it, let me give you the driect
anchor link for the pertinent section:

<URL: http://jibbering.com/faq/#FAQ2_3 >

And let me quote part of that section for you, specifically paragraph 6:
<quote>
When replying to a message on the group trim quotes of the preceding
messages to the minimum needed and add your comments below the pertinent
section of quoted material, as per FYI28/RFC1855 (never top post).
</quote>

The snippet about how to post on Google Groups is a way of letting
Google posters know how to quote without trying to be rude. I could of
course just say "Read the f**king FAQ" but I prefer to be a little more
helpful than that.

As for that snippet, it is indeed up for consideration in the next FAQ
Update. And if you wish, when it comes up, you are welcome to argue
against the groups desires for people to quote. I doubt you will get far
but it is your choice and opportunity to do so.

Watch for a thread entitled FAQ Updates or something to that effect.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
 
Reply With Quote
 
Joachim Zobel
Guest
Posts: n/a
 
      10-27-2005
On Wed, 26 Oct 2005 21:08:47 -0700, Farhadi wrote:

> before, I had included my js files thruogh Script block at the HEAD.
>
> now I want to include them using XMLHTTPRequest [..]


For another alternative, you can read scriptaculous.js.

Sincerely,
Joachim


 
Reply With Quote
 
Joachim Zobel
Guest
Posts: n/a
 
      10-27-2005
On Wed, 26 Oct 2005 21:08:47 -0700, Farhadi wrote:

> before, I had included my js files thruogh Script block at the HEAD.
>
> now I want to include them using XMLHTTPRequest because of 2 reason: 1. I
> want to load scripts on onload event of body. to speed up loading of page.
> 2. I dont want my scripts be saveable thruogh "Save As" at browser.


Do you really think these reasons are worth the effort and the additional
error prone complexity? 1. will not give you much unless you have >100kb
of script code. 2. is just a luser stopper. Real men GET with telnet.

> and I want to run my script just like including them on a script block.
> is there any more ways?


You could try including with script blocks at runtime by adding
those script tags to the head using DOM.

Sincerely,
Joachim

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
FWSM/PIX and Dynamic PAT using global IP range vs. global interface vs. global IP Hoffa Cisco 1 10-25-2006 06:50 PM
FWSM/PIX and Dynamic PAT using global IP range vs. global interface vs. global IP Hoffa Cisco 0 10-25-2006 01:04 PM
DataBinder.Eval and Eval. craigkenisston@hotmail.com ASP .Net 1 06-16-2006 05:33 PM
DataBinder.Eval for an object's property property... like Eval(Container.DataItem,"Version.Major") Eric Newton ASP .Net 3 04-04-2005 10:11 PM



Advertisments