« first day (971 days earlier)      last day (3975 days later) » 

12:00 AM
lol @rlemon why does lemonmeme.com/demos/audio.html just keep saying "dun fucked up"
 
is it possible to have divs with same id but holding a different value so with js you can collect them like an array (think like a checkbox)
 
@Dave Yes, it is. Probably a bad (use an actual array) idea but surely possible.
 
or even in pure js
 
bad in what way?
is there a more elegant solution
 
12:06 AM
you can ust have [index] pareameter on get by tagname
 
Separation of concerns
 
i use divs with hover/selcted effect for my checkbox
as they are easier for custom images over actual checkboxes with CSS
 
id is made to identify singular things, or if they are for css purposes only then they dont have a great deal of functionality which is why js would perfer otherwise
 
i know but i need to group the checkboxes some how so i can collect which ones are selected
using input element is not so elegant when it comes to making your own images for them
 
use class?
and reserver id for functionality (js)
 
12:09 AM
data attributes.
 
so get divs with the same class and check its .value
 
@phenomnomnominal What?
 
guys
 
Dave can you give a clear consice idea of what you want to accomplish?
 
12:10 AM
gals
 
If he HAS to use divs, then ids don't seem like a good idea
 
maybe a fiddlw?
 
I want to learn more about modular programming in jQuery, could you suggest me a blog post or something?
 
@phenomnomnominal Data attributes are satan :)
 
@BenjaminGruenbaum, whatever!
 
12:10 AM
@O0oO0oOO0ooO Read Resig's book.
@phenomnomnominal They are, really. When you use them little baby kittens die.
 
what, you mean ninja book?
 
ok heres html example:

<div id="chkbox" value="1" class="selected"></div>
<div id="chkbox" value="2" class="unselected"></div>
they have on click events to change the class (for appearance changes) i would there for in that situation only recieve id 1
 
@BenjaminGruenbaum, because of backwards compatibility or what?
 
@Dave, so just use something like $("#chkbox")[0] and $("#chkbox")[1]
 
@phenomnomnominal Because they show lack of separation of concerns and storing model data in the DOM. The dom is for presentation logic. You shouldn't use it to store your data, it's not what it's for. Using data attributes in the dom except for the purpose of binding or stuff like Angular directives indicates extremely poor design and understanding of how software should be structured in my humble opinion.
 
12:13 AM
actualy no, i mean $("#chkbox").eq(0)
 
i have to get only the ones selected mind based from className?
 
The DOM should not contain your business logic.
@O0oO0oOO0ooO sure, whatever.
Why would you like to store data in HTML elements? Don't we have objects for that?
 
@BenjaminGruenbaum what?
 
because user clicks the divs they want to select how will JS know which id's that is without having values assigned to them ?
 
$(".classname").eq(0)
 
12:15 AM
the div's are created via JS in the first place they all start off unselected
@TrevorRudolph what does .eq do ?
 
@Dave So you have closure access to them, great! Use an array to store accessors to their values. No need for jQuery or anything. Certainly no need for any selectors.
 
if you have 3 different things with .classname then it differentiates between them
 
oh i see @TrevorRudolph
 
the first one with that classname is .eq(0) then 1, then 2
 
@BenjaminGruenbaum not sure i follow the accessors?
 
12:17 AM
do you know jquery?
 
i don't use jquery
 
@TrevorRudolph jQuery is not an answer to this problem. Suggesting it shows lack of understanding.
 
i know but it can help
 
@Dave If you create a simple, reduced fiddle on jsfiddle.net or codepen.io I can show you.
 
i use no library other than my own made functions
@BenjaminGruenbaum ok gimi a bit
 
12:18 AM
@Dave No, it really can't. It offers no advantage in this particular problem.
 
!!s/gimi/Gimli/
 
@SomeKittens @BenjaminGruenbaum ok Gimli a bit (source)
 
I agree with data attributes if they are holding some presentation data, like for a compatible slider or custom menu
 
@phenomnomnominal sorry if that last message came out harsh. I really believe that data attributes are a horrible broken approach though.
 
@Dave, you can use jquery with purejs, just use $("#chkbox").eq(0)[0], any jquery selecctor with a [0] at the end turns it back into pure js, or you can do $("#chkbox").eq(0).get(0)
 
12:19 AM
im not installing an entire library for this one issue
altho installing is the wrong word to use
 
> you can use jQuery with purejs // WAT
 
@BenjaminGruenbaum, no I get what you mean, not harsh at all!
 
@TrevorRudolph You keep saying that, but that code is actually easier without jQuery
 
I think it really depends on what you use then for. If I need to set a temp title for a custom tooltip data attributes are a dream
 
@TrevorRudolph you can do everything without jQuery it just takes longer :P
 
12:20 AM
@rlemon What's wrong with that title attribute? I completely agree with storing presentation data in them though. I just find that in practice that's rarely the case.
There is very little presentation data that does not in fact need to be backed up by a view model.
 
Year, like proper jquery ;)
fucking mobile...
Once dataset is fully supported I would like to see it as more of a data binding approach (with modifications to dataset ofc)
 
I can see Angular getting native support in Google chrome, and Google offering a framework that would allow you to develop native apps with it, as well as additional tools.
 
@BenjaminGruenbaum jsfiddle.net/hxBk7/6
 
Looking :) One sec
What would you like to do, store the data about them?
 
i need to get only the selected ones from an onclick
 
12:30 AM
How many divs do you want? let's say 5?
 
ok lets say 5 for now
 
I'm writing it in a long way, it can be made shorter but I'm trying to make it clear
 
its ok ill shorten it myself after it :P
 
There you go
no data attributes, no abuse of IDs, no abuse of anything, just the plain ol' JavaScript
 
so when user submits the form how would i collect only the selected ones?
via the class name?
 
12:35 AM
No, that would be silly :) give me one second
See, in practice you don't ever, ever need to use query selectors except for scraping
I'm yet to see a good use (maybe when you don't have a choice when using plugins)
 
oh
so should i assign a value to them
 
I made some changes to illustrate the point
Note how I don't have a single selector
Now you have actual models, and state
Each such view model contains its state, which is the text in it, and whether or not it was selected
You can easily serialize them as JSON if you'd like (just call .stringify on that array) or perform other easy manipulations on them
@TrevorRudolph I suggest you look at it too, no jQuery involved
 
is checked a part of div' attributes or can you just make up any attribute name
i always thought check applied to input elements
 
No, we back up our HTML here with a view model.
 
ah ok
 
12:45 AM
The view model is the actual object we're working with. We have Status objects that represent our data.
 
guna test it with my real data from my server for divs object
 
First make sure you understand it well :)
 
yeh its alot better than my current method :P
 
Read about separation of concerns of some patterns of how UI should be structured.
It'll help you a lot.
 
thank you :)
 
12:56 AM
@BenjaminGruenbaum +4 karma
 
nice
I thought you were object.create zealot?
 
I was? Oh snap!
 
prototypical purity must not be disgraced like this
 
I love object.create , I don't see any inheritance here though.
Prototypical inheritance is for sharing functionality, not information. You can't clone an object with Object.create as far as I know.
(Did you see my answer to that objects question and the following argument with Aadit about this subject?)
 
12:59 AM
nope
 
@BenjaminGruenbaum You have gained karma for extensively helping the newbies understand basic concepts
 
Ah, cool :)
 
Aadit is a object.create zealot though
he even wrote blog post about it
 
No, I know him from before, he's just having a hard time to decide :) I read his blog, that argument was not his first here.
 
apparently object.create allows you to multiple-inherit
whereas constructors don't
 
1:01 AM
I just don't see how someone could say "I use classical inheritance as a pattern all of the time" and then write "it's a really bad idea to try to implement classical inheritance in JavaScript."
I think people just have a really hard time understanding how inheritance works in an implicit, duck-typed system.
I know I had originally. If it was my code Status would have probably generate objects and not a constructor, not that it matters really.
 
it is much shorter than writing property names over and over again in object literal
 
var a = {speak:function(){alert("Animal Speak");}};
var b = {drive:function(){alert("Vroom Vroom, driving");}};
var c = {speak:function(){alert("Meow");},drive:function(){alert("I'm a cat on wheels");}}
 
waddup kids
 
The type of c inherits from both the type of b and the type of a. Multiple classical inheritance in JS. Of course that all depends on my contract.
This sort of typing forces me to have to define my contract a lot better with documentation in testing. Still, I'd argue I can accomplish a stronger notion of classical inheritance here than in, let's say Java.
I just need to have a clear spec (which is why while I think classes for JS would be pretty useless, interfaces would be something I'd be interested in)
 
multiple inheritance implies multiple parallel prototype pointers
not a single vertical line
 
1:07 AM
@Esailija Huh? Why would it imply multiple parallel prototype pointers?
 
@Shaun314 Welcome to the JavaScript chat! Please review the room pseudo-rules. Please don't ask if you can ask or if anyone's around; just ask your question, and if anyone's free and interested they'll help.
 
Why would it have anything to do with prototypes at all? Just because JS supports prototypical inheritance doesn't mean we need that (awesome) system to do classical inheritance.
 
but there is no inheritance you just made functions with same name
if I change b in anyway, c will not be affected at all
 
@Esailija What is inheritance?
 
getting the methods from somewhere else basically
so that stuff is centralized
 
1:09 AM
@Esailija If you change b in a way that causes c to not satisfy the LSP in regards to b the contract would be broken yes. It is up to you the developer to keep that contract, nonetheless it's there, and you're able to observe c polymorphically as a b for all matters concerned.
 
I don't mean broken, I mean not affected at all
 
Of course it's not affected. I think we might be talking about slightly different things
 
if you have multiple inheritance like var c = {__proto1__: a, __proto__2: b }
if that were possible, then they would be reflected in c
 
I'm talking about the notion of subtyping and you're talking about sharing functionality and behavior across objects.
You can build prototypical chains for sharing functionality, or use stuff that getOwnPropertyName loops through the properties and copies them manually if you want to share code. That was not what I was referring to though :)
 
you can but they are again cast in concrete on C, and new changes are not reflected in it
 
1:14 AM
You'd like changes made to B after C is created to reflect in C?
If you're telling me I can't implement that in a classical world easily you're right. There are of course lots of design patterns dealing with it (like registry/repository etc).
 
if you extend or monkeypatch B, they will not be reflected in C at all, it is in no way inheriting from B
and this is what you can even do in classical languages
 
Wait, there are two things here.
 
in C# you can have extension methods and in ruby too
 
One is subtyping (which holds)
One is sharing functionality.
(Also, C# extension methods are just syntactic sugar for statics created to make LINQ fun)
 
everything is syntactic sugar dude
:D
 
1:16 AM
:)
Subtyping holds, there is no argument there. In my above example, as long as I don't add properties dynamically to B or A, C is a subtype of both B and A (depending on the contract)
When I add properties to an object I change its type
Not to mention that, in languages like C#, you can't monkey patch objects just like that (No, I don't mean the DLR and ExpandoObject and the such).
The point was not sharing functionality though, classical inheritance is pretty stupid for that in JS imo
 
why is that stupid? it works pretty well for many things
when there really is a hieararchy that makes sense and is not forced on
 
We're discussing here using classical inheritance for sharing functionality in JavaScript.
Also, I'm still confused what you mean. Are you talking about sharing code, or about subtyping? Those are different. My above example exemplifies strong behavioral subtyping but no method to share code, or keep it DRY.
(You have classes there, they're just implicit)
 
I don't really what I'm talking about of course
 
You don't really what?
 
He doesn't what he is talking about
 
1:22 AM
;d
 
Ah thanks, that makes
 
but you're saying clasiccal inheritance is stupid in JS pretty much
 
No, of course not
 
2
 
it is good for sharing functionality, if it's not, then you should use something else
 
1:25 AM
Sharing data
Sharing data is something prototypical inheritance does not address at all
 
@BenjaminGruenbaum, didn't catch that, over
 
if you have reference types in prototype, you can share that
 
Class.prototype.sharedData = []
 
What? Over.
 
1:27 AM
this.sharedData.push( value )
that.sharedData.pop()
is that not shared data?
 
I meant across inheritance
function Person(name){
    this.name = name;
}
function BigPerson(name,size){
     this.name=name; // <- I want `Person` to handle that logic
     this.size = size;
}
Simplified example
 
you would just delegate to the person constructor with .call
 
//JS Classical inheritance, in practice one also needs to fix the prototype chain
function Person(name){
    return {name:name};
}
function BigPerson(name,size){
     var p = Person(name);
     p.size = size;
     return p;
}
 
or even put the person constructor in the prototype
then you can do this.personConstructor(name);
no .call
 
1:29 AM
Yeah, there are several ways to solve it, but prototypical inheritance does not address them.
 
^ Very impressive, over.
 
@phenomnomnominal pretty damn impressive. Looks like real muscles.
 
And it's real time. Over.
The contact deformations at joints are amazing. Over
 
you mean pure prototypical inheritance
but there is no reason to be restricted to that except zealotry
 
We're in agreement about that .
The way you get properties from the prototype chain, but when you set them its only on this instance is one of the most confusing things to people starting with JS. People tell them that prototypical inheritance addresses the same issues that classical inheritance does in languages like Java, when in fact it's completely different and addresses some very different problems (though some similar ones too).
 
1:34 AM
yeah I cannot relate to someone who has learned it from Java and coming to JS
I first learned everything in JS and then Java etc..
it was very fast to learn Java/ActionScript/C# etc classical inheritance for me
 
ActionScript does both IIRC
 
Also ^ is Amazing. Over.
 
it probably can do since it's ecmascript extension but in practice it looks a lot like Java
(As3 btw)
 
You have a dual inheritance system there. You can just use classes which mean classical inheritance, or declare the class dynamic which would cause classical inheritance. I think AS3 sucks though.
(Having said that, I really liked it when it just came out. Then again, I was confused)
 
1:36 AM
isn't that the perfect language though
if you can use both, then you just have it all
 
No, in retrospect I liked AS2 better than AS3. AS3 made AS tedious to devleop. Stuff took longer to make and it was less fun. The typing also sucked.
It felt closer to Java than to AS2 or JavaScript.
They worked very hard to convince us that it was all for performance. With V8 today, I find that very ironic.
 
in theory it is much faster than v8
 
I was one of the first ones to adopt AS3, even used sneak peeks before it was officially out as a language. I loved it back then, being the less experienced developer I was.
 
if everything else is equal, then you just cannot make dynamic language as fast as static
 
So what?
 
1:40 AM
well for some applications that means you have to use static language
 
A good dynamic language engine runs much faster than a mediocre static one.
 
because the ceiling performance of dynamic language is not enough even in theory for that application
 
Just look at Java before Lars Bak came along and made it fast. It was a really slow language, I don't know if you remember, but 10 years ago the argument against Java was that it was slow.
 
well yeah it was interpreted
 
(Then he pretty much did the same to JS)
Still, it was static, I think JITs are getting better and better at this.
 
1:41 AM
I mean interpreting byte codes is still faster than interpreting script code but same shit in the end
 
I'm not saying static languages don't have a place. I'm saying making AS3 typed like that (AS2 was optionally typed btw) was really stupid.
 
and there are other things too, with byte code you need byte code verifier apparently
isn't AS3 optionally typed too
 
For some systems, statically typed isn't enough, for embedded systems you can't use a managed language often because it's not efficient enough with GC.
@Esailija In a much, much more annoying way.
I guess I just like high-level language coding
 
I cannot decide between static and dynamic actually
 
I coded too much statically typed code to like anything but dynamic languages :)
I would appreciate a way to enforce strong typing, but that's another story.
 
1:47 AM
being able to write code for hours without having to run or test it and have it pretty much work is awesome on one hand
 
I still test and run it though.
 
although this might be because I haven't used the awesome JS IDEs you mentioned yet
but I still cant believe they can work so well without at least annotations or something
 
Download WebStorm, it runs on windows/mac/linux and has a 30 day trial, spend at least 5 days learning how to work with it. (You can/should use annotations if you want it to catch typing errors, but it'll catch other stuff just fine without em).
It understands context pretty well.
Anyway, I'm off to sleep :) Good night.
You should implement a JS engine in JS that does JIT, that'd be pretty awesome and a great learning experience.
 
lol,. ok night
 
wonders if someone ported V8 to JavaScript with emscripten
 
1:51 AM
well someone has just emscriptened spidermonkey
but I don't see the point for learning experience in that
you pretty much just glue stuff together until it works is what I believe?
that is if it doesn't work out of the box
 
@RobertoHernandez Welcome to the JavaScript chat! Please review the room pseudo-rules. Please don't ask if you can ask or if anyone's around; just ask your question, and if anyone's free and interested they'll help.
 
@BenjaminGruenbaum there is js.js ... it's not really what you asked for
 
hi all
 

« first day (971 days earlier)      last day (3975 days later) »