« first day (593 days earlier)      last day (4354 days later) » 

7:00 PM
@gowri did you tried GXmlHttp ?
 
GXmlHttp i m not aware on this
can u explain
 
maybe it was a third-party script i don't really remember
 
oh God
 
no it's in v2 doc
I think you can perform what you're trying to do with that
 
Thanks for the hind i will check this out. If you have furthur knowledge please share with me
 
7:06 PM
My best knowledge is : read the API doc
 
@DieVarDump: i add GXmlHttp.create(); this code just above GDownloadUrl(searchUrl, function(data) {
but still the same
 
@Neal the chat just wants you to say "hey" is all
 
7:28 PM
var request = GXmlHttp.create();
request.open("GET",searchUrl, false);
request.send(null);
var xmlDoc = request.responseXML;
@DieVarDump: i tried in this way
but luck
 
is it XML you're trying to get ?
 
@rlemon Haha that is what it seems ^_^
 
yes
 
oh but, XMLHttpRequest is async
you won't be able to perform it like thast
 
7:52 PM
Anyone have any input on a better way to implement a factory in javascript? I asked a question here:

http://stackoverflow.com/q/10840316/1026459
 
i really thing you need to prototype
 
I did one with prototype, and one without. I ended up liking the one without.
Why do you think it needs prototype?
 
because you can extend the class and it won't hog memory like a bitch?
it seems you are trying to force some entirely different language into javascript :P
I was thinking of posting this:
    var createFoo = function() {
    	var id = 0;

    	function Foo() {
    		this.id = null;
    	}

    	Foo.prototype = {
    		constructor: Foo
    	};

    	return function() {
    		var ret = new Foo();
    		ret.id = id++;
    		return ret;
    	};
    }();
what do you think
 
Hum
 
I am a little new to constructors in javascript, could you explain what constructor: Foo does?
 
8:02 PM
BEcause i like separate files, i would not do it like that
bue it'll works and it's definitely better
 
the created objects will have a shared .constructor property which will refer to the function that consturcted the object, i.e. Foo
actually that's what my macro generated, there is no point in doing that since there is no methods
it turns class Foo into
 
The main point of this is the have an array of Foo held that can be accessed and can return unique Foos
 
function Foo() {

}

Foo.prototype = {

	constructor: Foo
};
where is the array
 
so can you do var foo = new Foo(); ?
it is in the foofactory
 
yes
 
8:05 PM
oh right, I didn't notice
 
:)
 
well if you have a factory, you never have to new Foo()
 
better use a object literal with id's as keys
o(1) vs o(n) lookup
 
because the factory is here to do it
 
I have an autoincrement unique id for each foo
the factory calls new foo. do you mean when I define foo I shouldnt use the new keyword?
 
8:06 PM
var createFoo = function() {
    	var id = 0,
    		allFoos = {};

    	function Foo() {
    		this.id = null;
    	}

    	Foo.prototype = {
    		constructor: Foo
    	};

    	return function() {
    		var ret = new Foo();
    		ret.id = id++;
    		allFoos[ret.id] = ret;
    		return ret;
    	};
}();
 
(why don't instaciate a Foo with the id ?)
 
of course the factory calls new foo
lol I don't know
 
ok ^^
 
the only public interface here is createFoo
which returns foos
you can't call new Foo from outside
you can call new ( createFoo().constructor ) though
 
can you give an example of how you would use that to make two unique foos in the array? Just createFoo(); twice?
 
8:09 PM
yeah, and it's not array
 
its an object, right :P
can foos ever be accessed after initiation?
 
the outside code can't access the allFoos object
anytime you call new Anything an unique object is constructed
 
luckily, or else it would be impossible to create dom elements from a base configured one :)
they would just end up all the same lol
 
you would add methods in the prototype object like this:
Foo.prototype = {

	method1: function() {
		return this;
	},

	method2: function() {
		return this;
	},

	constructor: Foo
};
 
Anyone care to answer a question about optional URL parameters?
 
8:14 PM
they are automatically shared by all the instances, and only created once
if you put that stuff in a function, then those functions are created anew each time the parent function is called = memory hog
 
Yeah, automatically shared means that prototype functions cannot operate on unique foos. It will make changes to all foos
 
no, the function is shared, not this
the functions are generic but they operate on whatever the this binding is
so if a method is called on foo1 that does this.abc = 1 it won't affect anything else that might use that function, it will only set .abc = 1 for that particular foo1 object
I can see you are again expecting too much magic from javascript :D
 
lol
I am trying to pigeonhole it into c#
 
so yes, obj1.method === obj2.method but they encapsulate their own data
so it doesn't matter if they share the same function
 
If a prototype contains an array, then it seemed to me that all the objects shared that array.
 
8:19 PM
you don't put data in prototype
especially non-scalar
prototype = shared, methods can be shared = methods go into prototype
 
Oops :P
 
data = should not be shared, data doesn't go into prototype
 
var __foo = function(){
this._Children = [];
};
__foo.prototype = {
_fooId = null,
etc...
}
I have done that, and it seems that the id was still unique
 
any time you set data on object, it will be put on that object only
any time you get data from object, if it's not on the object, it will be looked up from its prototype chain
note that data can be functions, arrays, scalars whatever
in javascript functions are just values
 
When passing optional URL parameters, does each option have to be separated by an '&'?
 
8:22 PM
I see, so then null in that case was the shared data that they all had. But if it was changed it would be scoped to just the object which was changed
 
yea
 
@Brent - Unless you deserialize it elsewhere
 
unless you explicitly change the data on prototype
 
yes
 
if you change data on prototype, it will affect every object
Array.prototype.shuffle = function(){} ... now every array has shuffle method
 
8:23 PM
so the prototype in that case kind of works as a constructor then which is what I was after
 
Thanks guys!
 
even those that were constructed before that assignment
 
Right, but I don't want to extend it in this current implementation
 
sure, it was just an example
 
I am sure that comes in handy though
 
8:25 PM
it can be pretty hard to grasp initially but once you get it you'll laugh at how primitive and simple it really is
 
I didn't notice much of a difference in memory usage between prototype and new function implementations.
 
it depends how much data there is to hold in a closure, how many instances you create, and how many functions are you creating per instance
the data held in a closure is also not owned by the object, but the closure
the object merely stores a reference to a closure
it's not the primary owner anymore
so anyone can steal that closure and use it as its own
 
not if it is instantiated
 
there is no reason to instantiate if you are gonna use closures anyway
 
var ff = new __fooFactory();
var bar = new __fooFactory();

allows me to configure two sets. mostly I do this to make it easier to type out ff.CallFunction() is nice
 
8:31 PM
if you are not gonna use prototype model then this is what you need at most
function createObject () {
	var wannabePrivate = "5";
	return {
		method1: function(value) {
			wannabePrivate = value;
		}

	};
}
it doesn't matter if I call it with new or directly or whatever
it doesn't matter that it's the base object
var obj = createObject(); var trolls = {}; trolls.lol = obj.method1; trolls.lol() <-- this now affects obj
 
Sorry to bust in here.
I'm pretty new at javascript and objects. Can somebody tell me how to solve this?

server = function () {
	this.status;
	this.socket;

	if (!window.WebSocket) {
		this.status = "Unsupported";
		return;
	}

	this.status = "Connecting";

	this.socket = new WebSocket("ws://localhost:8181/");

	this.socket.onopen = function () {
		this.status = "Connected";
	}
}

var test = new server();

alert(test.status); // always "Connecting"
 
well it doesn't affect obj per say, it affects the closure's data
but obj is pretty irrelevant now
because it doesn't own any data
 
One is fine, but multiples is where the complications come in when sharing data.
 
@ZippyV What is there to solve? This looks like something for node.js
 
The last line on my code sample: test.status will never be set to connected even when I am connected.
 
8:36 PM
Maybe I am just fighting the language too much. I could probably port all this to c# and just use $.ajax to get a jsonp and then manipulate that.
It is just that interacting with the server can be exponentially slower than native javascript.
 
you can always write in languages that transcompile to javascript
 
I can write a factory in c# and then compile it into javascript?
 
well no, but there is Dart, CoffeeScript, JSX and so on
 
I have seen those, but I was never really that impressed.
I drink coffee and write script, doesn't that count?
 
and yea don't fight the language
 
8:38 PM
well I didn't start it :)
 
why are you using new __fooFactory()
factory implies that it will build a new object regardless
new is just a special function call
 
because each factory is set up to produce a different type of objects
 
it says fooFactory.. why could it build anything else than foos :P
 
I also have an affinity for the new keyword I suppose
I would rather be able to use ff instead of __fooFactory() all the time too
 
see if that helps you understand your issue
 
8:41 PM
If I have candyFactory I expect it to produce candy
 
server = function () {
this.status;
this.socket;
var self = this;

if (!window.WebSocket) {
this.status = "Unsupported";
return;
}

this.status = "Connecting";

this.socket = new WebSocket("ws://localhost:8181/");

this.socket.onopen = function () {
self.status = "Connected";
}
}

var test = new server();

alert(test.status);
 
@used2could ok, you could have used a fiddle like me instead of a wall in the chat :P
 
meh
 
@ZippyV pretty much 'this' in the scope of the onopen function does not refer to the class object you have created.
iirc it should refer to the websocket ?? or possibly the window object?
 
8:43 PM
@rlemon - The issue was having an array of unique MyClass inside of ClassFactory.
 
this still was not in the correct scope
 
Sorry, my issue, not the other one
 
ohh... well I wasn't dealing with your issue
 
@rlemon only 12 lines of code and it's already complicated
 
and haven't been.
 
8:44 PM
Ohh lol, my bad
 
@ZippyV ok, in your code "this" in the scope of the onopen function is not refering to the same object as 'this' outside that function
you are setting the property 'status' of a different object. so of course it won't change.
 
@ZippyV, Google "javascript variable scope"
 
try this
function Server(url) {
    this.status = "Connecting";
    this.socket = new WebSocket(url);
    this.socketOpened = this.socketOpened.bind(this);
    this.socket.onopen = this.socketOpened;
}

Server.prototype = {

    socketOpened: function() {
        this.status = "Connected";
    },

    constructor: Server
};

var test = new Server("ws://localhost:8181/");

window.setTimeout(function() {
    alert(test.status);
}, 1350);​
 
@ZippyV jsfiddle.net/eUJZs/1 look at my comments here
 
@Esailija, good call on the prototype approach but i'm sure that's just as complicated to @ZippyV
 
8:50 PM
thats why I avoided it
:P
 
lol
 
it has nothing to do with prototype, that's just good practice
 
lets get him understanding scope first
 
it has to do with proper binding of this
and calling alert right away?
 
i would have used console (eww, who uses alert) but again.
 
8:51 PM
I'm sure you could do a one-liner to connect a websocket properly
 
The alert call was just for demonstration purpose
 
did not think it would be readily transparent what they should do
 
yea I would just write test.status in console
because it should be connected by the time your fat fingers type it
 
@Esailija, Your approach is extremely elegant. I like it
 
well thank you :P
 
8:53 PM
7 minutes and i'm tapping out the clock. Come on clock!
 
What's the difference between using .prototype and putting the socketOpened function inside function Server() ?
 
Google javascript variable scope
 
functions inside functions are created everytime the parent function is called
actually
I just wrote an answer for that
0
A: Why would you create a variable with value this

EsailijaI don't think one really wants to do that: Any time an instance is created, you also create a "copy" of the function. So 5 instances, will create 5 "copies" of the function. That "copy" of a function is bound to an environment that is only relevant to that specific instance, so it cannot be use...

If you want to see indentation gone wild, look here: paste.ubuntu.com/987876
 
lol double tab?
 
it's like 8 levels deep
 
8:59 PM
jesus
 
@Esailija what would you have done differently dawg?
 
attach methods in some object and bind them to current context as needed
preferably prototype but there was no class here I think
it was all just inline code
 
Thanks everybody, it looks like my code is working now.
And I'll definately look into this .prototype stuff
Any tutorial links?
 
I don't have a link for you.
 
@Esailija the code is all so similar
 
@user973810 yea it's just logging the responses pretty much
 
@DieVarDump: I solved my problem.. thanks for your helps
1
Q: Gmap missing XMLHttpRequest header

gowriI am using symfony framework to develop web site. Symfony recognize ajax call by XMLHttpRequest header. I have integrated Gmap on my page. Gmap making ajax request without XMLHttpRequest header.So symfony doesn't recognize ajax request. Normal jquery ajax call have this header. X-Requested-W...

 
v8 also optimizes the normal prototype usage to a very good extent
 
Quitting time. Thanks again for the enlightening and entertaining diversions.
 
9:17 PM
see you
 
Hey guys, is there any reason why this wouldn't work as a client-side require() equivalent?

var require = function(files, callback){
	var requireCount = 0;

	var requireFile = function(filePath) {
		requireCount++;

		xhr({ uri: filePath + '.js', method: 'get' }, function(response){
			eval(response);

			requireCount--;

			if (requireCount === 0){
				callback();
			}
		});
	};

	files.forEach(function(file){
		requireFile(file);
	});
};
Usage: require(["file1", "file2", "file3", function() { alert('files have been required'); });
xhr is $.ajax equivalent if you're wondering
 
What does not work exactly ? The alert does not pop up ?
 
The alert goes up, but let's say file1's content is var test = "hello world", if I do:

require(["file1", "file2", "file3", function() { alert(test); });

test is undefined...
 
eval is local
 
oh crap
is there any way of making it global? so it would execute the scripts like if I was <script> including them?
 
9:31 PM
(1, eval)( "code")
 
wut?
 
or new Function("code")()
not sure about new function though
 
Oh interesting article, thanks :D
 
yea a long time ago since I last read it
 
I wouldn't try to replicate PHP behaviour. Look at how raynos does it
 
9:34 PM
Where?
 
I don't know :-P somewhere at github
 
with jQuery you can use dataType: "script" though
and it will global eval the response
the module loader is pretty popular wheel for reinvention
 
That works awesomely with the article's code
 
I say the top 3, in no particular order
1. inheritance
2. module loaders
3. template engines
hmm though I cant fit MV* frameworks in there now
 
10:05 PM
@Esailija - I tried a version of your suggested implementation for generating an object with some naming conventions to use in an API for creating an element.

        //custom dropdown names
        var createContainerNames = function () {
            var id = null, name = null, parent = null;

            function Names() {
                this.id = "Phases_" + phaseCounter + "__ContainerId";
                this.name = "Phases[" + phaseCounter + "].ContainerId";
                this.parent = "phases" + phaseCounter + "Container";
 
Hello. What is the correct jquery method to call if you want the user to click a form (or tab to it for that matter) and then something else pops up, outside the form?
 
can you use fixed font
edit your message and on the right there is the fixed font button
the outer functon is supposed to be called immediately
by adding (); at the end
 
Ah, and so by not doing that it wasn't instantiated for re-use?
I didn't think it needed to be self-executing
 
how are you using createContainerNames
it doesn't return new Names until first execution
after that it starts returning new Names objects
which is why in my original code there was the initial execution
 
I added }(); and still get undefined
I am using it just to make a log entry
you can see it at the very bottom
 
10:11 PM
those are variables
id is not a property of anything
I mean..
 
lol
facepalm
 
the first execution returns the factory function, further executions of course then call the factory function and each call returns a new object
 
sweet, ok, working now :) although I suppose it was never broken.
thanks!
 
10:24 PM
hello
 
 
1 hour later…
11:33 PM
@Esailija thanks for that :-/ after my "nap" i now probably is going to hae some serious code with messy ports
 

« first day (593 days earlier)      last day (4354 days later) »