Jump to content
Larry Ullman's Book Forums


  • Posts

  • Joined

  • Last visited

JasonC's Achievements


Newbie (1/14)



  1. Still learning, find this interesting. I'm not a programmer, more of a hobbyist.
  2. Appears perhaps to be making use of a dispatch table and late binding, described briefly at http://designpepper.com/blog/drips/using-dispatch-tables-to-avoid-conditionals-in-javascript
  3. Thanks! Just spent much of the night getting PHP to post to the Twitter API by hand coding myself, hopefully this is easier.
  4. Larry, is there a broken link on this page (http://www.peachpit.com/articles/article.aspx?p=1998951&seqNum=4)? A few lines down, the following is written: NOTE You can download the complete script here. But there's no link. I'd be interested in seeing the script, is it available somewhere?
  5. I have a similar problem not fixed with the above solution. For some reason, Postfix on my Mac (running OSX 10.6.8) is setting the "From" as coming from the Apache User (_www on my machine), despite the PHP headers and despite the -t flag above. My real-world email server then rejects the email because _www is "Not our Customer (in reply to MAIL FROM command)." If I change the Apache user to my user name for my real world email account, everything works fine. I have usually had the Apache User set to my login name on my Mac, but have read this is not a good idea, Apache should be running under its own login, so I switched it back to the defaults. This is esoteric, maybe, but if anyone has advice, it would be appreciated! Meanwhile, I will keep Googling away and reading up, looking for solutions. I suspect the fix is easy, but finding it is not...
  6. Okay. This is probably the most challenging Javascript code I've tried to understand. I think I now understand theoretically what's going on. I'm wondering how one would change the code to make it more explicit what is happening while still keeping the X function syntax the same? Maybe using the call, apply, or bind methods? I'm not a programmer by training, just someone who uses Javascript and finds it interesting. I know some BASIC and some C, so I'm more familiar with the imperative paradigm than OOP. So I'm learning, but this pattern seems to be unusual. I find three things in this example especially interesting: 1) scope 2) use of out as a container like an array using BOTH associatively and numerically indexed elements, and the length of out does not include counting the associative elements 3) use of the closure (simple closures I can follow, but this one not easy to follow, at least for a beginner in closures) - it's hard to find m, for instance, in a defined state Larry, an advanced Javascript book by you would be awesome.
  7. That's awesome, thanks! Give me some time to work through this, there's a lot going on.
  8. All right, after tearing this function apart, reporting variable values at every step to both the console using console.log and also to the page using document.write, I think I understand what's going on, at least a bit more. The for/in loop seems to be creating methods and assigning JUST the function STATEMENT to the new method name, not invoking it; e.g., "out[hide]" = "function (x) {out.map(m, x);return out;}". The only time I can get "m" to return a value is WITHIN the for/in loop, otherwise I get the error "ReferenceError: m is not defined". I don't understand why "m" is not being replaced with the meths[meth] definition, but the linkage to it does appear to stick, I assume through closure? This is tricky. It doesn't help that Firefox's console.log does NOT always show the same info as document.write, so sometimes I get different messages back (document.write provided more info, sometimes console.log just showed "function" - not as useful).
  9. I've read the entire thread many times, and I'm still working on understanding this. Changing the immediately invoked function expression to the wrapper function makes it clearer, but I'm still trying to understand the inner workings of what is going on. My primary difficulty is understanding what is happening with the map method, what exactly is being assigned to what, and when and where the methods are being invoked when the X object is used. I understand the map method's definition, but this is not a simple example of its use. I understand this has something to do with functional programming? It would be more helpful for me if things were made more explicit. I also don't understand how method chaining is being implemented here, although I know you can return "this" in designing functions to enable such a pattern - and indeed, if I change "return out" to "return this" inside the for/in loop, everything still works fine. I'm getting there, but this is very tricky! It's very cool, though - this way lies making one's own framework, yes?
  10. I'm learning from various sources and can usually puzzle out what's going on, but this has me a bit stumped. I came across this code at http://www.webdeveloper.com/forum/showthread.php?224180-JQuery-how-does-it-s-insides-work: function X(css){ //dom utility //a couple of node harvesters, using id and tag name... function el(id){ return document.getElementById(id);} function tags(elm){return document.getElementsByTagName(elm);} //collect output: var out=[]; if(css[0]=="#"){//id out.push(el(css.slice(1))); }else{//tags out=out.concat([].slice.call(tags(css))); };//end if id or tagName //define some methods for the utility: var meths={ hide:function(a){a.style.display="none";}, show:function(a){a.style.display="";}, remove:function(a){a.parentNode.removeChild(a);}, color:function(a){a.style.color=this||a.style.color;}, size:function(a){a.style.fontSize=this||a.style.fontSize;} };//end meths //bind the methods to the collection array: for(var meth in meths)(function(n,m){ out[n]=function(x){out.map(m,x); return out;} }(meth, meths[meth]));//next method return out; }//end X dom utility For the life of me, I am having a hard time figuring out how the Javascript is running in the for loop binding the methods to the collection array. I realize this is advanced, but if someone could walk through what is happening, and how the methods are being called with variables correctly linked to their respective methods, it would be appreciated. This is cool, if only I could understand how it is occurring.
  11. Found the answer, I guess, at http://stackoverflow.com/questions/153598/unknown-column-in-where-clause
  12. I'm just trying to use an alias in a select query and I'm having a problem. It's not a big deal, but I don't know why I'm getting an error. Can anyone answer this: Why does SELECT title, text, id FROM memos LEFT JOIN memos_associations USING (id) WHERE CONCAT_WS(' ',title,text) REGEXP '[[:<:]]potassium[[:>:]]' = 1 work ok, but SELECT title, text, id, CONCAT_WS(' ',title,text) AS combo FROM memos LEFT JOIN memos_associations USING (id) WHERE combo REGEXP '[[:<:]]potassium[[:>:]]' = 1 not? The latter generates the error, "ERROR 1054 (42S22): Unknown column 'combo' in 'where clause'." Thanks! ...Jason
  13. I found the problem. I had "submit" as name and id in the HTML for the submit button, somehow that was messing up the Javascript. Changed the id and name to "submitButton" and now the script works like you would think it would. Good grief!
  14. Okay, this is driving me crazy. I have a form that I am trying to submit using Javascript. I get a reference to the form with the DOM, add submit() to it, but I get an error in the Firebug console, "TypeError: document.getElementById("loginForm").submit". Any idea why this won't work? Page 379 gives an example where this should work, but also makes the point that "doing this does not actually trigger a submit event." I can get around the problem by generating a click() action on the submit button, but why doesn't submit() work?
  • Create New...