Newsgroups: comp.lang.javascript
From: Lasse Reichstein Nielsen <l...@hotpop.com>
Date: 03 Jul 2003 18:14:26 +0200
Local: Thurs, Jul 3 2003 12:14 pm
Subject: Re: Using setInterval inside an object
"Daniel" <sorry-no-em...@i-get-virus-and-spam.com> writes: That is a step on the way to understanding, making the concepts fit > First, let me say that my use of words like "morph" and "become" > shouldn't be taken too literally, at least not in the programmatical > context; the context should be my way of putting my understanding > into human, easily digestible, words. inside ones head. However, words that make sense in your mind, often ends up making little or no sense when taken out of that context. :) Or, as somebody once said: You haven't really understood something > But still, I don't see the anonymity of the "original" MyObject function I think you are putting the parentheses in the wrong places. The code was > being the result of function expression, since it isn't anonymous before > after it's been called. Up until that point it does exist as MyObject, as a > definition yes, but it still has a reference... var anObject = function(){...} (); I think you are reading it as (var anObject = function(){...}) (); i.e., assign the function value to the anObject variable first, then var anObject = (function(){...} ()); i.e., create anonymous function, call it, and assign the return value to I had to read it twice too, to be sure what happened. I would have put > To me, a truly anonymous function expression would be something like Indeed. > myArray.sort(function(a,b){ return subCmp(a[label],b[label]); }); > ...And then you write this: > > var anObject = funciton(){ There is no "anObject" function. If you bound the function first, say using > > return new Array(); > > }(); > > ^- It is the pair of brackets after the function expression that > > execute it (in-line and once only). > But how can that be true? As I see it, the (); calls whatever's returned by (anObject = function(){...}) (); (without the "var" so it is legal), then anObject would be a function, but the "()" would call that function, not the value returned by it. The returned value is actually lost. > And, if I write The execution goes like this: > var oneOff = function() { > var test = new oneOff(); > - I get "1 2", which means oneOff is parsed before the inner function, yes? 1 : create anonymous function (a "function expression"): > So, as I see it, if, this is somehow similar to the pseudo-code: > var oneOff = function(){ /*code*/ }(); var oneOff = /* code */ ; except that code need not be an expression. It can contain statements and local variable declarations. Writing function () { ... }() merely creates a local block and a scope. ... > What I meant by "object constructor *function* object" and "object I would just call it "constructor function" > *constructor*" was this: > var blahblah = function() { > var myinstance = new myconstructor(); I would just called it "object", "instance of myconstructor" or > ^ And that would become my "object *constructor*" "constructed object". Shorter is (sometimes) better :) > I confused myself there, actually =) I'm not used to classes, since in That is much closer to Javascript than most languages then. Javascript > Actionscript everything is essentially an object (or a prototype). I just > saw it in your code, and thought, well... Don't know what I thought, really > :P is a prototype based (as oppesed to class based) object oriented language. I sometimes wish there was a clone method on all objects, but one can Object.prototype.clone = function () { > Man, I really want the next words you say to be, "Actually I think you *do* In that case, I actually think you *do* get it (apart from a minor > get it, Daniel, but for God's sake, man, work on your ability to precisely > explain what you mean!" > If nothing else, I truly understand why > alert(function(){ return function() { return true; }}()()); > Gives me an alert box with "true" written in it. detail about how function application and assignment associates), Daniel, but for your own sake, work on your ability to precisely explain what you mean! > Argh! :) It's tough work getting smarter. But FUN!!! You'll go far with that attitude :) > PS: Richard, thank you for all this, it's really great to have my mind > challenged - it's been a while ;)! /L 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.
| ||||||||||||||