Two Plus Two Poker Forums

Two Plus Two Poker Forums (https://forumserver.twoplustwo.com/)
-   Computer and Technical Help (https://forumserver.twoplustwo.com/48/computer-technical-help/)
-   -   Learning Javascript Thread (https://forumserver.twoplustwo.com/48/computer-technical-help/learning-javascript-thread-1223133/)

RICHI8 01-06-2013 07:44 PM

Re: Learning Javascript Thread
 
Two JavaScript programmers walk into a bar and immediately begin arguing with each other. Meanwhile, an Io and a Erlang programmer are sitting next to each other at the bar laughing their asses off.

sdturner02 01-07-2013 08:23 PM

Re: Learning Javascript Thread
 
Haha I just laughed pretty hard at that

Draidin 01-12-2013 11:46 AM

Re: Learning Javascript Thread
 
Hello Everyone,

Can someone explain what the script should look like for the event "activate" in scrollspy found in Bootstrap here: http://twitter.github.com/bootstrap/...html#scrollspy?

This is the event that highlights the links as you scroll through the content on a page.
I have been searching and trying different scripts but cannot nail it. I am very new to JS.

Thanx if you are able to answer!

sdturner02 01-13-2013 11:58 PM

Re: Learning Javascript Thread
 
Quote:

Originally Posted by Draidin (Post 36619337)
Hello Everyone,

Can someone explain what the script should look like for the event "activate" in scrollspy found in Bootstrap here: http://twitter.github.com/bootstrap/...html#scrollspy?

This is the event that highlights the links as you scroll through the content on a page.
I have been searching and trying different scripts but cannot nail it. I am very new to JS.

Thanx if you are able to answer!

Well what exactly are you trying to do?

suzzer99 01-18-2013 11:45 PM

Re: Learning Javascript Thread
 
It's been years since I bought a programming book. But I usually found the Cookbooks were pretty useful when learning a new language.

well named 01-22-2013 07:04 PM

Re: Learning Javascript Thread
 
Quote:

Originally Posted by Draidin (Post 36619337)
Hello Everyone,

Can someone explain what the script should look like for the event "activate" in scrollspy found in Bootstrap here: http://twitter.github.com/bootstrap/...html#scrollspy?

This is the event that highlights the links as you scroll through the content on a page.
I have been searching and trying different scripts but cannot nail it. I am very new to JS.

Thanx if you are able to answer!

$('.navbar li').on('activate', function() { ... });

assuming you have jquery

Nchabazam 02-22-2013 09:29 PM

Re: Learning Javascript Thread
 
I want to bump this old flamewar just to point out that having started getting more heavily into JS/JS frameworks the last few weeks, like 1/2 of the tutorials/stackoverflow questions seem to be in coffeescript. I can follow it well enough, but I do need to sit down and learn it, because it seems like it's becoming more widely spread. It also does look simpler and at least for me, less different from ruby/rails.

Also, front end has become way more fun since I started messing around with backbone. It's also fun to structure all my rails controllers/models to be restful APIs, as a bit of a different challenge.

RICHI8 03-03-2013 05:34 PM

Re: Learning Javascript Thread
 
Rendering HTML client-side is a challenging, fun and rewarding experience. There are certainly perils that come with it. Testing and performance are two that come to mind.

I'm glad to see you're learning/getting into CoffeeScript, though. A similar framework to Backbone, but written in CoffeeScript, is Spine. I wouldn't recommend using it due to it not being actively maintained, but reading its source code can be quite enlightening.

http://www.spinejs.com/docs/index

Shoe Lace 03-03-2013 07:26 PM

Re: Learning Javascript Thread
 
I've been learning and working with Angular lately, I'm really enjoying it. The API is pretty clean, good documentation, not a lot of boilerplate, good run time performance = pretty awesome combo.

e i pi 04-30-2013 04:49 AM

Re: Learning Javascript Thread
 
Code:

var TodoList = Backbone.Collection.extend({

    ...

    remaining: function() {
      return this.without.apply( this, this.completed() );
    },

  ...

TodoList.completed() returns an array, is the bolded line just a quirky javascript way to pass arguments from an array into a function?

Nchabazam 04-30-2013 06:51 AM

Re: Learning Javascript Thread
 
Quote:

Originally Posted by Shoe Lace (Post 37437132)
I've been learning and working with Angular lately, I'm really enjoying it. The API is pretty clean, good documentation, not a lot of boilerplate, good run time performance = pretty awesome combo.

I know this post is months old, but angularjs is awesome. I'm building an app that's getting fairly decent sized at this point with a rails backend... it's really fast, easy to use, and powerful.

I wouldn't call the documentation good though... but there's quite a solid community behind it so stackoverflow and blog posts can get you through most things.

suzzer99 04-30-2013 09:20 AM

Re: Learning Javascript Thread
 
Quote:

Originally Posted by e i pi (Post 38291035)
Code:

var TodoList = Backbone.Collection.extend({

    ...

    remaining: function() {
      return this.without.apply( this, this.completed() );
    },

  ...

TodoList.completed() returns an array, is the bolded line just a quirky javascript way to pass arguments from an array into a function?

The entire array should be passed as an argument. So the apply function would get 2 arguments.

e i pi 04-30-2013 10:11 AM

Re: Learning Javascript Thread
 
right. I was just confused because I think of apply and call as being used to control the value of "this" and seeing it used just to pass in an array of arguments looked odd.

Tim Brice 05-01-2013 02:25 PM

Re: Learning Javascript Thread
 
I have been following the Javascript is Sexy post (too lazy to link). So far, so good. It recommends Professional Javascript if you have any programming knowledge and I would agree with that. It is a good book.

Mariogs37 05-04-2013 11:31 AM

Re: Learning Javascript Thread
 
Am trying to come up with a medium-level difficulty JS project. Any ideas / inspiration?

Maybe a todo list?

Also, whenever I look up AJAX info I always run into this:

XMLHttpRequest

But when I look up how to incorporate AJAX into Rails, the syntax is totally dif...usually something like:

$.ajax {
:url => '/rankings',
:type => 'get'
:data => 'json'}

Any idea what this is about? It has me pretty confused since it doesn't mention XMLHttpRequest at all...

suzzer99 05-04-2013 11:52 AM

Re: Learning Javascript Thread
 
$.ajax is doing an XMLHttpRequest under the covers.

Mariogs37 05-04-2013 12:41 PM

Re: Learning Javascript Thread
 
ahh

e i pi 05-06-2013 02:44 PM

Re: Learning Javascript Thread
 
backbone question,

Drupal is a bit special and expects some attributes to be in nested arrays like this,

Code:

model_property[und][0][value] = "some model value"
I know there is a .parse method for responses, which I already set up. Is there something like this for requests? Right now I'm fishing around in the .sync method but want to make sure I'm doing this right.

suzzer99 05-06-2013 03:55 PM

Re: Learning Javascript Thread
 
Are those really nested sequential arrays or just objects (or a combo)? Can you be a bit more specific as to the problem?

FYI - model_property['something'][0]['somevalue'] is the same as model_property.something[0].somevalue

e i pi 05-06-2013 06:42 PM

Re: Learning Javascript Thread
 
Sorry, I wasn't clear. The property['und'][0]['value'] is on the server side in php.

So on the client side I have a model with attributes like model.title = 'some title', model.content = 'some content'. But on the server side it expects a json object like,
Code:

{
  "title": "some title",
  "content": {
    "und": [{"value": "some content"}]}
}

I overrode the Backbone.sync with the following modifications to get it working,

from
Code:

    if (options.data == null && model && (method === 'create' || method === 'update' || method === 'patch')) {
      params.contentType = 'application/json';
      params.data = JSON.stringify(options.attrs || model.toJSON(options));
    }

to
Code:

    if (options.data == null && model && (method === 'create' || method === 'update' || method === 'patch')) {
      params.contentType = 'application/json';
      var modeldata = model.toJSON(options);  // I added this line
      modeldata.body = {und: [{value: model.body}]};  //and this line

      params.data = JSON.stringify(options.attrs || modeldata); //changed
    }

it works now but I'm curious about best practices. whenever I tried to change the params.data json directly it would fail validation somewhere and cut out my modifications so I copied the object and altered it before turning it to JSON and it seems to work.

I just realized it wasn't failing validation I was just adding properties to a string object. :\

Mariogs37 05-07-2013 05:55 PM

Re: Learning Javascript Thread
 
Quote:

Originally Posted by suzzer99 (Post 38354436)
$.ajax is doing an XMLHttpRequest under the covers.

Is there a good source on this? The rails docs kinda suck for how rails implements AJAX...

candybar 05-07-2013 08:49 PM

Re: Learning Javascript Thread
 
Quote:

Originally Posted by Mariogs37 (Post 38403038)
Is there a good source on this? The rails docs kinda suck for how rails implements AJAX...

This has nothing to do with rails btw:

http://api.jquery.com/jQuery.ajax/

Mariogs37 05-08-2013 12:14 AM

Re: Learning Javascript Thread
 
this is perfect, didnt realize it was a subset of jquery for some reason

thanks a ton!

Mariogs37 05-08-2013 11:40 AM

Re: Learning Javascript Thread
 
So as of right now, I have a JSON object coming back from my AJAX request. I'm trying to use jQuery to append info from this JSON object but, instead of doing that, it simply prints the JSON object to the screen (looks like an array of strings)...

Code:

  $('#rankings_link').click(function(){
    $.ajax({
      dataType: 'json',
      url: '/rankings',
      type: 'get'
    }).done(function(received_data){
      for (var m = 0; m < received_data.length; m++) {
        $('#rankings ol').append('<li>' + received_data[m] + '</li>');
      }
    });
  });

Any idea what the issue is?

Grue 05-08-2013 11:50 AM

Re: Learning Javascript Thread
 
JSON/javascript objects don't have a length, you're thinking of an array. turn your json object into an array value so that you iterate through it.


All times are GMT -4. The time now is 08:22 PM.

Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.

Copyright © 2008-2020, Two Plus Two Interactive