« first day (134 days earlier)      last day (4813 days later) » 

6:06 PM
Hello everybody
I have a little question about jQuery html() . How does it work? It's not like innerHTML in pure JavaScript? So, it is correct If I build html construction in a string way, and then just insert it in an object by html()
or better way is to use DOM methods like append, insertAfter and so on.. ?
 
@IvoWetzel there is a difference!
@Innuendo I would use DOM methods. String manipulation might be marginally faster (benchmark it)
 
@Raynos That is?
goes to read the spec
 
@Raynos, but if DOM methods are slower, what is their advantage?
 
@Innuendo string manipulation is ugly and hidieous
@IvoWetzel '"' "'" The difference is that an unescaped ' or " becomes invalid ;)
 
dun dun DUN!!!!
 
6:15 PM
@Innuendo using innerHTML is plain wrong.
No there is no difference
 
yeap, I understand, but how jquery html() is worked?
$("$smth).html("<h3>Test</h3");
Is like document.getElementById("smth").innerHTML("<h3>Test</h3>");
??
 
@Innuendo yes but its .innerHTML=
It does some other clever stuff to
You can also pass a function to .html()
 
Oh, tnx. Didn't know about source viewer
 
Hi again! :)
 
So if i pass string of "<tags>" it still use innerHTML
 
6:28 PM
@Innuendo Use backticks (`) to format code! If you want to post multi-line code, post it in a separate message and before sending the message, press Ctrl+K or the fixed font button.
This is some inline code
   Don't do this.
   myFunction();
Either comment these lines or post them in separate messages.
// This is OK.
myFunction();
This is also OK.
myFunction();
 
7:05 PM
I guess I shouldn't leave this chat open when I'm away for a day or two
796 unread messages!
 
@IvoWetzel Sorry for being thick, but see this:
// A factory for creating a  scheduler function that's "bound" to a specific api instace
function Scheduler(api) {

    // return the anonymous, "bound" function
    return function(method, options, interval) {
        var id = null;
        function request() {
            api[method](options);

            // set a timeout so that the event loop calls the function again, this is NOT recursive
            id = setTimeout(function() {
                request();

            }, interval);
        }
Is it bound because this changes?
 
no it's because the returned function closures a specific API instance
 
The word closure confuses me, does it mean it kills that API instance?
As in that sense of closure?
 
nope
A closure closes around on a scope and stores it for later use
vs an anonymous function which has no binding to local scope
 
So that instance is stored in ram etc and then called back to when needed?
 
7:12 PM
kindof.
Think more of it as the current stack is saved and re-used later
 
So it stores the var values for that instance in a place to be reused?
 
since it's already in memory
 
The program realises that a local variable is used outside the function so the local variable is saved.
 
@Raynos okay thats what I was thinking :)
 
function foo() {
    var local;
    return function(i) {
         if (i) {
              local = i;
         } else {
              return local;
         }
    }
}
 
7:15 PM
then the anonymous function acts as a wrapper to hand back the values generated within it?
 
JS doesn't have support for specifiying a variable by name, does it?
 
eval!
...
 
var a = foo();
a(2);
console.log(a());
 
@Raynos so there you are creating an instance of the function?
thus naming the function a()
 
the local variable isn't destroyed after the function foo ends a function that uses it was moved outside function
foo just returns a wrapper for the local variable
 
7:17 PM
yeah thats basically what i meant
so closures always include anon functions?
 
yeah. The important thing is that is a closure because you can access the state of local after foo ends
not always
 
Now, here's a question...:
 
function foo() {
    function bar(i) {
         if (i) {
              local = i;
         } else {
              return local;
         }
    }
    var local;
    return bar;
}
 
@Raynos And I can access it within the var a because it has been instantised?
 
function foo() {
    var local = 'bar';
    return function() {
        eval('alert(local);');
    }
}
^^ That function, what will it alert?
 
7:18 PM
@MylesGray that works without an anon function
@ircmaxell cant remember eval scoping.
 
So it is a function that returns an inner function?
 
yes
 
@ircmaxell If you call it as foo()(), yes…
 
eval = what you can do in the console right?
 
and bar can look in the scope of bar and the scope of foo
@MylesGray eval is a bit more funny then that. But close enough
 
7:20 PM
@Raynos okay good i understand that now
why is eval bad then?
 
So it's the entire scope that's copied, not just what the compiler thinks is needed...
 
@ircmaxell Im guessing since you asked it would return null or undefined?
 
well, it would return either undefined or bar
undefined if it's compiler determined, bar if the whole scope is copied
 
So if eval = null, if no eval = bar?
 
@MylesGray what?!
 
7:23 PM
@MylesGray eval allows you to run code as a string
eval("(function() { alert("foobar"); }())");
 
as a string? as in... print code onto a page without execution?
Or just with no white-spacing?
 
As in pass source code into eval and it runs it
eval also greats a new instance of the javascript interpreter and is slow & unsafe
 
right okay, like a self-contained environment?
so it is separate from the environment enclosing it?
 
eval is also parsed at runtime instead of at parse time
so scoping can't be determined by the compiler
which is why the question
 
Not really
eval("window.undefined = "I'm breaking your code");
 
7:27 PM
I meant scoping can't be determined prior to execution
 
so are there any REAL world applications that would be a valid call for eval?
 
user1385191
I think it was google who said they use it for parsing json quickly
 
as it acts async?
 
okay an last question, what do the square brackets around the method do, and why doesn't this cause a recursion loop:
 function request() {
            api[method](options);

            // set a timeout so that the event loop calls the function again, this is NOT recursive
            id = setTimeout(function() {
                request();

            }, interval);
        }
 
7:32 PM
because it's not recursion
although in a sense it is recursion. Just not directly
 
api[method] <- method is a string it just calls api["foo"] (== api.foo)
 
oh so it is implementing yet another extension of the api instance?
 
where did you get that API code from?
 
it's Ivos
He went through my code an refactored it
I am just trying to understand it
 
oh
want me to refactor ivos refactoring?
 
7:39 PM
lol
The reason for avoiding direct recursion is to prevent locking the browser. This way you have unlimited depth possibilities, and other code can run in between the levels...
 
@ircmaxell recursion = infinite loop with no breaks?
I.e. just executes as many times as is possible until something goes "pop"
 
no
close, but not really
recursion is self reference
 
user1385191
it's calling a function from inside itself
 
function recursion(){
     recursion.apply(this, arguments);
}
 
found this:
var property = 'bar';
var value = eval('foo.' + property);

Here’s the right way of doing the above:

var property = 'bar';
var value = foo[property];
so what ivo is doing is avoiding eval as it isnt known until runtime?
[method] i mean
 
7:44 PM
yes
 
righhhttttt
 
hes selecting the method from the object
 
user1385191
obj['prop'] is used for dynamic properties
 
You can even do obj['!@#&{#&test5358'].
 
@ircmaxell It is technically a self-reference though isnt it?
 
7:45 PM
@Nyuszika7H no you cant :p thats stupid
 
@MattMcDonald Not necessarily. You can have recursion without calling a function from itself
 
@Raynos yes you can :P
 
user1385191
so if you do a simple for loop that iterates 10 times, you can do obj[iterator] and have properties from 0-9
 
Well you just create an infinite loop of called functions?
 
The only requirement is that the access is self-similar
 
7:46 PM
@Nyuszika7H technically yes but I'm going to delete any c ode like that
 
function foo() {
    bar();
}
function bar() {
    foo();
}
that's recursive even though it's not self-referential directly
 
yeah like that!
thats exactly what i was thinking
 
Recursion is the process of repeating items in a self-similar way. For instance, when the surfaces of two mirrors are exactly parallel with each other the nested images that occur are a form of infinite recursion. The term has a variety of meanings specific to a variety of disciplines ranging from linguistics to logic. The most common application of recursion is in mathematics and computer science, in which it refers to a method of defining functions in which the function being defined is applied within its own definition. Specifically this defines an infinite number of instances (functi...
 
as long as you create a non-escapable loop
 
It doesn't have to be non-escapable
in fact, a good recursive algorithm has a exit state which will collapse the recursion
 
user1385191
7:47 PM
yep
 
user1385191
otherwise, it can turn into a pseudo continuous while loop
 
night :)
 
It just has to be self-similar
night @Nyuszika7H
 
@Nyuszika7H night man
 
@MylesGray: if you want a better grasp on that stuff, I have 2 books I'd suggest you read
 
7:49 PM
@ircmaxell what are they?
 
I'll have a look at them :)
So escapable recursion =
Recursion
If you still don't get it, see: "Recursion"
 
user1385191
foo(0);

function foo(num)
{
	if(num < 10)
	{
		foo(++num);
	}else
	{
		return;
	}
}
 
Yup, you have a grounding state which causes the recursion to terminate
 
user1385191
note that using num++ will cause a "too much recursion" error
 
7:54 PM
That bit is explained quite well in I Am a Strange Loop
 
user1385191
because the num is getting sent without updating the value
 
but I'd suggest reading GEB first. It's a life-changing book for everyone I know who's read it
241
A: What is the single most influential book every programmer should read?

Tim HowlandFor a truly deep read, I'd suggest Douglas Hofstadter's Gödel, Escher, Bach. He dives pretty deep into many of the issues that programmers face every day- recursion, verifiability, proof, and boolean algebra. Great read, a little off the beaten path, occasionally challenging, and extremely reward...

 
Quick javascript question?
If I have :
<textarea id="ttt" cols="30" rows="20"> </textarea>
 
@David19801 quick!! quicker!
 
Whats the javascript to change the row number (20) to a variable var rows=30?
quick enough?! :)
 
so I do ttt.row=30?
sorry, i'm new to js syntax
 
well, not exactly
 
document.getElementById("ttt").row = 30
 
^^ that
 
cool, gotcha thanks guys!
 
8:01 PM
You may want to learn a bit more rather then hack away piece by piece ;)
 
user1385191
great, ExternalInterface crashed my browser for the nth time this weekend.
 
lol
 
user1385191
the 10.2 update might go down as one of the worst ever
 
this is a big upgrade
/me hopes it doesn't break my computer
210 package updates
 
8:17 PM
How do I make a form "glow" and rounded and 2.0?
 
2.0?
 
user1385191
web 2.0
 
its cool, i've just found a generator...thanks!
 
wow web 2.0, haven't heard that since 2006
 
lol
 
8:29 PM
Wait?
This is the web 2.0 ?
 
dynamics = web 2.0
that, drop-shadows and rounded corners
:P
web 3.0 = the semantic web
 
Web 4.0 = whatever kids are playing around with in their basements today
4
 
@ircmaxell I don't think anyone wants to know that :P
 
lol
 
 
1 hour later…
9:39 PM
Hi guys, any dojo experts here ?
 
9:53 PM
damn ie sucks so bad
i'm sorry, i had to get that off my chest :)
 
10:07 PM
@Roel its a bit bad
@Philippe what do you need?
 
10:22 PM
@Raynos Why does one of these loop into the other:
API.prototype = {
    lookup: function(resource, callback) {
        // build the url etc here
        this.request(url, callback);
    },

    request: function(url, callback) {
        // build a request here and send it
        request.on('finished', function() {
            callback();
        });
    }
};
and how does request.on() work O_o
I'm using JSONP, does it pick up the returned JSON data?
 
10:56 PM
@MattMcDonald Have you ever come across this before:
request.on('finished', function() {
            callback();
        }
what is the on method doing with the function?
 
user1385191
the on is calling the callback passed through the params
 
user1385191
beyond that, I still haven't figured the rest of it out
 
11:16 PM
hmm i think ill try extract some more info from ivo tomorrow
check this out:
2
A: Prototypes and nested return functions, help!

Martin JespersenLets break it down into it's parts //create function API which is meant to be instantiated into an object using ///var foo = new API(); function API(site, key, ...) { this.site = site; this.key = key; this.schedule = new Scheduler(this); } //create two prototype functions on the AP...

 

« first day (134 days earlier)      last day (4813 days later) »