Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.
You should be able to access the globals like jQuery just fine, it doesn't really go around clobbering everything because it makes use of dependency injection. Is everything loading properly in the first place? Any logs you can provide, how far is your angular apps execution going?

Adbot
ADBOT LOVES YOU

Smarmy Coworker
May 10, 2008

by XyloJW
It loads up the page but breaks scope when I try to use geoip because it isn't loaded until after it's referenced, since I have to GET from maxmind. I just now figured that out and loaded it before angular but I'm getting an e401 for some reason. At least the rest of the page loads fine :shrug:

As far as JQuery goes I have no idea, I might not even be using it right now -- I'll have to check. I thought I was.

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.

ARACHNOTRON posted:

It loads up the page but breaks scope when I try to use geoip because it isn't loaded until after it's referenced, since I have to GET from maxmind. I just now figured that out and loaded it before angular but I'm getting an e401 for some reason. At least the rest of the page loads fine :shrug:

As far as JQuery goes I have no idea, I might not even be using it right now -- I'll have to check. I thought I was.
If you want you can link me the code, I'm used to running initialisation on it with asynchronous dependencies. That said, if you wanna investigate yourself look into loading up angular explicitly rather than letting it bootstrap itself. Look up angular.bootstrap in the API, that'll allow you to control the loading of angular in more detail.

Wardende
Apr 27, 2013
Hi all,

I'm new to JavaScript and I want to use it to build a Spotify app. I need to be able to access a database of some kind with my back-end code. All my previous JS experience (such as it is) has been limited to client-side stuff, so I don't know what the best way of going about this is. I know that node.js is designed to be a back-end implementation of JS but this is a small project so it doesn't seem to me that using node is warranted. Or is it? Does anyone have any suggestions about how to go about interfacing JS and a database? Thanks!

karms
Jan 22, 2006

by Nyc_Tattoo
Yam Slacker

Wardende posted:

Hi all,

I'm new to JavaScript and I want to use it to build a Spotify app. I need to be able to access a database of some kind with my back-end code. All my previous JS experience (such as it is) has been limited to client-side stuff, so I don't know what the best way of going about this is. I know that node.js is designed to be a back-end implementation of JS but this is a small project so it doesn't seem to me that using node is warranted. Or is it? Does anyone have any suggestions about how to go about interfacing JS and a database? Thanks!

You don't? I don't see anything beyond "use our js stuff on an html page"?

Wardende
Apr 27, 2013
I don't think that there's any restrictions on what JavaScript you can use? I didn't see that in any of their developer docs. If that's the case then I may have to write it using their C API.

ambushsabre
Sep 1, 2009

It's...it's not shutting down!

Wardende posted:

Hi all,

I'm new to JavaScript and I want to use it to build a Spotify app. I need to be able to access a database of some kind with my back-end code. All my previous JS experience (such as it is) has been limited to client-side stuff, so I don't know what the best way of going about this is. I know that node.js is designed to be a back-end implementation of JS but this is a small project so it doesn't seem to me that using node is warranted. Or is it? Does anyone have any suggestions about how to go about interfacing JS and a database? Thanks!

It sounds like you might just want to use something built on top of node, you might as well if you want to use an entirely js framework. Maybe try Express?

Deus Rex
Mar 5, 2005

Wardende posted:

Hi all,

I'm new to JavaScript and I want to use it to build a Spotify app. I need to be able to access a database of some kind with my back-end code. All my previous JS experience (such as it is) has been limited to client-side stuff, so I don't know what the best way of going about this is. I know that node.js is designed to be a back-end implementation of JS but this is a small project so it doesn't seem to me that using node is warranted. Or is it? Does anyone have any suggestions about how to go about interfacing JS and a database? Thanks!

Wow, what a coincidence! I worked on the highest ranked Spotify app (TuneWiki) for over a year. I'm sure you know it but anything you build on your back-end code (e.g. in node.js, or Ruby on Rails or Django or something similar) will not be running inside Spotify. You will need to access your back-end server over HTTP from your Spotify app code. Generally speaking you'll want to do something like:

  • expose an HTTP API on your back-end which responds to requests with JSON data
  • write a Javascript/HTML client which sends AJAX requests to your back-end API and does things with them.

Normally this sort of thing (sending AJAX requests across domains or protocols) is a pain in the rear end, but Spotify allows apps to whitelist hosts which your app is allowed to send cross-domain requests to, which is very nice. Consult their sort-of-lovely documentation or their tutorial app for details.

I'm unemployed right now and have tons of free time, so feel free to PM me your email address or a Google Talk username and I'd be happy to help you out ther when I can. My email address and GTalk is tom@crystae.net

Wardende
Apr 27, 2013
Oh cool, awesome! I'll definitely be in touch. Thanks so much for offering to help! :)

ManiacClown
May 30, 2002

Gone, gone, O honky man,
And rise the M.C. Etrigan!

I'm trying to build a page that's going to dynamically look up systems from a database based on OEM, then power supplies compatible with those systems depending on OEM and type of system. I'm trying to do this with AJAX, but this is my first time using AJAX and I'm having trouble wrapping my head around it. Should I be using jQuery, or can I do it easily enough with vanilla AJAX?

Bruegels Fuckbooks
Sep 14, 2004

Now, listen - I know the two of you are very different from each other in a lot of ways, but you have to understand that as far as Grandpa's concerned, you're both pieces of shit! Yeah. I can prove it mathematically.

ManiacClown posted:

I'm trying to build a page that's going to dynamically look up systems from a database based on OEM, then power supplies compatible with those systems depending on OEM and type of system. I'm trying to do this with AJAX, but this is my first time using AJAX and I'm having trouble wrapping my head around it. Should I be using jQuery, or can I do it easily enough with vanilla AJAX?

You don't have to use jQuery, but jQuery has done the work of making it so XMLHTTPRequest is called the correct way on the different platforms so you don't need to do the cross-browser support yourself. I think there may be other frameworks may do that plumbing for you as well.

Themage
Jul 21, 2010

by Nyc_Tattoo
I'm having some trouble getting a script to work right, when you first load the page it executes correctly but when you click on the button to regenerate it refuses to work but on my local machine it works just fine. All the script does is make a 1280x720 canvas and draw randomly colored squares in a grid on it.

The script canvas.js
code:

var gridx = new Array();
var gridy = new Array();

window.onload = function init(){		
		start();

}

function gridArray(){
	for (var i=0;i<128;i++){
			gridx.push(i);
		}

		for (var j=0;j<72;j++){
				gridy.push(j);
			}
}

function start(){

		gridArray();
		test();
	
		for (var i=0;i<128;i++){
			for (var j=0;j<72;j++){

		gridDraw(gridx[i], gridy[j]);
		
		}
	}

}


function gridDraw(x, y){
	var canvas = document.getElementById('grid');
	var context = canvas.getContext('2d');

	x *= 10;
	y *= 10;

	var color = ['#FF0000', '#00FF00', '#0000FF', '#FFFF00', '#00FFFF', '#FF00FF', '#FFCC00', "#CCFF00"];
	var col = Math.floor(Math.random() * color.length);

	context.fillStyle=color[col];
	context.fillRect(x, y, 10, 10);


}



function test(){
	console.log(gridx.length+"\n"+gridy.length);
		console.log(gridx+" \n");
		console.log(gridy+" \n");
}

The HTML code
code:
<!DOCTYPE html>

<html>
	
	<head>
		<title>canvas fun</title>
		
		<script src="canvas.js"></script>
		<link rel="stylesheet" href="\grid\grid.css">
	</head>

	<body>
		<canvas id="grid" width="1280" height="720"></canvas>
		<form>
			<button id="butt" onclick="start()">Generate</button>
		</form>
	</body>

</html>

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Themage posted:

I'm having some trouble getting a script to work right, when you first load the page it executes correctly but when you click on the button to regenerate it refuses to work but on my local machine it works just fine. All the script does is make a 1280x720 canvas and draw randomly colored squares in a grid on it.

The script canvas.js
code:

function gridArray(){
	for (var i=0;i<128;i++){
			gridx.push(i);
		}

		for (var j=0;j<72;j++){
				gridy.push(j);
			}
}


You realize every time this function is called, your arrays are just getting bigger and bigger, since you never clear them out. Then your drawing code never references anything but the values set the first time. But seeing as how you are just storing numbers that are the same as your loop indexes, you can get rid of the arrays and this function entirely.

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

Themage posted:

code:
		<form>
			<button id="butt" onclick="start()">Generate</button>
		</form>

I'm going to say that it's the <form> tag. The browser submits the "form" when you click the button. Remove the form tag and it works.

Deus Rex
Mar 5, 2005

Wheany posted:

I'm going to say that it's the <form> tag. The browser submits the "form" when you click the button. Remove the form tag and it works.

alternatively remove the onclick attribute from the <button> and instead use an onsubmit attribute on the <form> tag (and use evt.preventDefault() where evt is the argument passed to the handler)

in this case yeah, just remove the <form> tag. but on a real form if you ever add a click event handler to the submit button instead of adding a handler to the form's submit event you're a bad person :)

Skiant
Mar 10, 2013

Deus Rex posted:

in this case yeah, just remove the <form> tag. but on a real form if you ever add a click event handler to the submit button instead of adding a handler to the form's submit event you're a bad person :)

Not just on forms.
I think it is a violation of Geneva's convention to use inline javascript event handlers in 2013. Or at least, it should be.

Deus Rex
Mar 5, 2005

Skiant posted:

Not just on forms.
I think it is a violation of Geneva's convention to use inline javascript event handlers in 2013. Or at least, it should be.

That's a separate issue and one I'm not totally sure I agree with 100% . In a large application you want to use jQuery or addEventListener (and probably some Backbone-like structure for constructing your views and managing events…), but for small one-off things it's simpler to do it this way.

The form submit event — my pet peeve — is an accessibility and usability issue (try using 'Enter' to submit a form that uses a click handler on the submit <button>).

Skiant
Mar 10, 2013

Deus Rex posted:

That's a separate issue and one I'm not totally sure I agree with 100% . In a large application you want to use jQuery or addEventListener (and probably some Backbone-like structure for constructing your views and managing events…), but for small one-off things it's simpler to do it this way.

The form submit event — my pet peeve — is an accessibility and usability issue (try using 'Enter' to submit a form that uses a click handler on the submit <button>).

Fair point.

I admit I'm a bit of an extremist when it comes to be super-organized from the ground up even for small projects, because in almost every job or side-project I had so far, there was always a moment where a small one-off became a huge, messy project full of spaghetti and no one wants/has the time to clean it up.

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.

Skiant posted:

Fair point.

I admit I'm a bit of an extremist when it comes to be super-organized from the ground up even for small projects, because in almost every job or side-project I had so far, there was always a moment where a small one-off became a huge, messy project full of spaghetti and no one wants/has the time to clean it up.

I'm contracting on one of these right now. No one wants to be the guy who says to the client, 'we need to stop adding/changing features because we need to pay back technical debt'.

Skiant
Mar 10, 2013

Maluco Marinero posted:

I'm contracting on one of these right now. No one wants to be the guy who says to the client, 'we need to stop adding/changing features because we need to pay back technical debt'.

I 've been that guy for 8 months in a previous job before they let me throw everything away and start fresh (there was literally nothing to salvage in that project).

It is a very delicate thing to do. Mostly, it boils down to peacefully presenting facts on how the current code is preventing you from working fast and well.
It takes a lot of patience, though. You also need basic people skills in order to avoid going full tantrum when faced with idiocy and incompetence, which will happen more than once if you take that kind of path. Prepare attack points by carefully picking identified issues, and always come up with a solution that provides multiple enhancements.


And it looks like I'm going to be that guy again in my new job (started last month). We're working with a set of nodeJS libraries written by one single guy from the team, and that dude is a terrible team player. He can't even be bothered to let us know when he changes something critical in the lib, because according to him, we should not need docs or anything, just read his code.

ufarn
May 30, 2009
d3.js question.

I still suck at selections and telling apart data from datum, and how exactly operating on data arrays (csv, tsv, json) work, but specific to this case, I am struggling with adding data point dots to a chart.

Take this multi-series line chart, and this article on adding the "dots" with this code:

JavaScript code:
svg.selectAll("dot")    
        .data(data)         
    .enter().append("circle")                               
        .attr("r", 5)       
        .attr("cx", function(d) { return x(d.date); })       
        .attr("cy", function(d) { return y(d.close); })     
        .on("mouseover", function(d) {      
            div.transition()        
                .duration(200)      
                .style("opacity", .9);      
            div .html(formatTime(d.date) + "<br/>"  + d.close)  
                .style("left", (d3.event.pageX) + "px")     
                .style("top", (d3.event.pageY - 28) + "px");    
            })                  
        .on("mouseout", function(d) {       
            div.transition()        
                .duration(500)      
                .style("opacity", 0);   
        });
If I had a single column of data, this would probably be easy enough, but how would I iterate over all the columns in creating a dot for each - in the same colour as their respective graphs?

EDIT: I think I found out what breaks - not how to fix it. The values d.name and d.temperature (d.close in the .dot code example) are not defined for the scope of the dot code, so I have write the code to retrieve them myself, from what I can tell. I think it might involve the datum() definition, but I'll take a look and see what I can surmise.

ufarn fucked around with this message at 18:25 on Jul 4, 2013

Smarmy Coworker
May 10, 2008

by XyloJW
I figured out most of my dumb Angular stuff but I'm really confused about how promises work. They're like deferred objects but not really and it's throwing me off a bit.

Real world codes here: I have an $http GET request where the Success and Error functions return an object containing some data that I need. I've split this off of my controller since it's not really controller stuff but I need my controller to access that object somehow. I thought maybe if I returned the result of the $http call since I figured it might work exactly like a deferred chain but no, I'm not getting anything back from it.

JavaScript code:
//it's kinda like

function(query, $http) {
  return $http.get("site", query, "whatever params go here").
    success(function(result, status) { return result; }).
    error(function(result, status) { return nope; });
};
Thoughts?

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

ARACHNOTRON posted:

I figured out most of my dumb Angular stuff but I'm really confused about how promises work. They're like deferred objects but not really and it's throwing me off a bit.

Real world codes here: I have an $http GET request where the Success and Error functions return an object containing some data that I need. I've split this off of my controller since it's not really controller stuff but I need my controller to access that object somehow. I thought maybe if I returned the result of the $http call since I figured it might work exactly like a deferred chain but no, I'm not getting anything back from it.

JavaScript code:
//it's kinda like

function(query, $http) {
  return $http.get("site", query, "whatever params go here").
    success(function(result, status) { return result; }).
    error(function(result, status) { return nope; });
};
Thoughts?


JavaScript code:
//maybe like

function(query, $http, controller_function) {
  return $http.get("site", query, "whatever params go here").
    success(controller_function(result, status)).
    error(controller_function(result, status));
};
EDIT: Hahaha, I forgot I changed my Avatar and I was confused for a minute :downs:

Smarmy Coworker
May 10, 2008

by XyloJW
That is certainly an option, and I can't believe I hadn't thought of it. Thanks. It just seems a little anti-MVC to me but I'll mull it over this weekend and probably go ahead with it anyway.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

ARACHNOTRON posted:

That is certainly an option, and I can't believe I hadn't thought of it. Thanks. It just seems a little anti-MVC to me but I'll mull it over this weekend and probably go ahead with it anyway.

Not sure how that would be "anti-MVC" as it makes the function very generic, since passing in the function to be called on AJAX return decouples it from any specific "caller" class. If it bothers you, there's other ways to do it via delegation and so on, but I don't see any sort of MVC violation here (although I think primarily of SmallTalk / Cocoa when I think MVC, so we might come from different places there.)

Strong Sauce
Jul 2, 2003

You know I am not really your father.





Javascript is asynchronous so you can't just return results so you have to use callbacks.

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.

Strong Sauce posted:

Javascript is asynchronous so you can't just return results so you have to use callbacks.

Except you can 'almost' get it like that if you use promise structures, like Angular's stripped down implementation of Q, which are incredibly powerful once you get your head around them.

After writing an indexedDB/websql library in them I just love them to bits. They'll make reasoning and passing around asynchronous operations/results so much more flexible and easy to manage without inadvertently creating race conditions

Smarmy Coworker
May 10, 2008

by XyloJW

Lumpy posted:

Not sure how that would be "anti-MVC" as it makes the function very generic, since passing in the function to be called on AJAX return decouples it from any specific "caller" class. If it bothers you, there's other ways to do it via delegation and so on, but I don't see any sort of MVC violation here (although I think primarily of SmallTalk / Cocoa when I think MVC, so we might come from different places there.)

It just seemed a little wrong to me to work even a miniscule amount of data manipulation into a controller-class function but I suppose considering that I'm parsing/formatting to send off to other areas and the view it's totally "fine". I'm just scared to stray from extremely strict definitions!!

Fruit Smoothies
Mar 28, 2004

The bat with a ZING
I need a textarea with bold support, so I'm using a div with contenteditable. Unfortunately, I need to manipulate what's being entered. At the moment, I'm starting with this

code:
<div contenteditable="true">
	<b>Hello</b><br/>
	World.
</div>
The idea is to replace all the <b> tags with <i> tags. The problem is dealing with the cursor position, as every time the html is altered, it returns to the beginning.
My method, therefore, is as follows:

1) On keypress, setTimeout to the tag replace function to allow the element to accept the keypress event.
2) the timeout function gets the cursor position, makes the html changes, and then reinstates the cursor position.
However, in this code, the element loses focus afterwards and afaik, the cursor position is ignored.

code:
$(element).keypress(function() {
	var range = document.createRange();
	setTimeout(function() {
		var sel = window.getSelection();
		var current = $(element).html();
		var bPos = current.indexOf("<b>");
		var bePos = current.indexOf("</b>");
		//while(bPos >= 0) {
			current = current.replace("<b>", "<i>");
			bPos = current.indexOf("<b>");

		//}
		//while(bePos >= 0) {
			current = current.replace("</b>", "</i>");
			var bePos = current.indexOf("</b>");
		//}
		$(element).html(current);
		// range.collapse(true);
		sel.removeAllRanges();
		sel.addRange(range);
		$(element).focus();
	}, 10);
});
Any help would be much appreciated :)

leftist heap
Feb 28, 2013

Fun Shoe

ARACHNOTRON posted:

I figured out most of my dumb Angular stuff but I'm really confused about how promises work. They're like deferred objects but not really and it's throwing me off a bit.

Real world codes here: I have an $http GET request where the Success and Error functions return an object containing some data that I need. I've split this off of my controller since it's not really controller stuff but I need my controller to access that object somehow. I thought maybe if I returned the result of the $http call since I figured it might work exactly like a deferred chain but no, I'm not getting anything back from it.

JavaScript code:
//it's kinda like

function(query, $http) {
  return $http.get("site", query, "whatever params go here").
    success(function(result, status) { return result; }).
    error(function(result, status) { return nope; });
};
Thoughts?

In my own controllers/services, I usually follow a pattern like this:

JavaScript code:
//In my service definitions

.service('SomeService', function($http){

	this.someFetch= function() {
		return $http.get('some-url');
	};
});

//Then in calling code

SomeService.get().then(function(data) {
    //Some stuff with the data
}, function(error) {
    //Some stuff with the error
});
Mainly I like this because it looks clean and the service itself doesn't have to worry about the callbacks.

dereekb
Nov 7, 2010

What do you mean "error"?
Got a fairly simple question for you guys.

So I'm learning JQuery/Javascript and currently have a piece of code that is responsible for updating the visuals for a list of elements.

This is what it looks like:

code:
...
		for (var i = 0; i < websites.length; i++) {
			var copy = websiteReference.clone(true);
			var website = websites[i];
			var websiteNumber = website.number;
	
			//Unhide the copied <li> element
			copy.toggleClass('hidden', false);
			copy.toggleClass('website', true);

			copy.find('.website-header').html('Website ' + websiteNumber);

			var titleField = copy.find('.website-title');
			titleField.val(website.title);
			titleField.bind('input', function() {
				var title = titleField.val();
				[b]website[/b].title = title;
			});

...

			var deleteLink = copy.find('.delete-website');
			deleteLink.click(function() {
				removeWebsite([b]website[/b]);
			});

			copy.appendTo(websitesList);
		}
The problem is that the website that is referenced in each of those functions (that I bolded) are set to the final website that is referenced from the array of website objects.

As a said, I'm learning Javascript but am familiar with OOP programming so to me this seems like those function parameters become singletons and are just updated with the latest value that is input.

How can I solve this problem?

Strong Sauce
Jul 2, 2003

You know I am not really your father.





You need to look up what a closure is, and what an IIFE is. Also need to know that Javascript is scoped by function, not by block.

Essentially the variable `website` is not scoped within the function of bind.input nor within the function of the deleteLink.click event. Thus when you exit that loop, the value of website is websites[i] where websites[i] is the last element of the array.

To fix this you need to wrap those functions within a closure/IIFE to force `website` into the correct scope of those functions.

E.g.
code:
var i, website;
for (i = 0; i < websites.length; i++) {
  website = websites[i]
  function(website) {
     // website now binds to websites[i] where i is the current loop variable.

     website.bind('click', function() {
         alert('yoyo');
     });
  }(website) // <--- this is set as websites[i] from line #2
}

Strong Sauce fucked around with this message at 08:06 on Jul 12, 2013

dereekb
Nov 7, 2010

What do you mean "error"?

Strong Sauce posted:

You need to look up what a closure is, and what an IIFE is. Also need to know that Javascript is scoped by function, not by block.

Essentially the variable `website` is not scoped within the function of bind.input nor within the function of the deleteLink.click event. Thus when you exit that loop, the value of website is websites[i] where websites[i] is the last element of the array.

To fix this you need to wrap those functions within a closure/IIFE to force `website` into the correct scope of those functions.

E.g.
code:
var i, website;
for (i = 0; i < websites.length; i++) {
  website = websites[i]
  function(website) {
     // website now binds to websites[i] where i is the current loop variable.

     website.bind('click', function() {
         alert('yoyo');
     });
  }(website) // <--- this is set as websites[i] from line #2
}

Thanks for the explanation! I understood closure but didn't realize it was scoped by function instead of the block as you said.

I actually managed to fix it by passing the website as a parameter into the bind function:

code:
...
			var deleteLink = copy.find('.delete-website');
			deleteLink.bind('click', website, function(event) {
				var website = event.data;
				removeWebsite(website);
				return false;
			});
...
Since that sets the scope properly, although I might rewrite it to fit your example since it'll be shorter.

On your example, is the (website) at the bottom a typo and supposed to be part of the comment?

code:

  function(website) {
...
  } //(website) <--- this is set as websites[i] from line #2

Thanks again!

Edit: When you say is "scoped by function", you mean the singleton that that function is created as? To me it means it ends up being the equivalent of a static function/class in Java where the website that is mentioned reads from what would be equivalent to static value; is that the case here, or am I wrong to think of functions as objects?

dereekb fucked around with this message at 08:37 on Jul 12, 2013

Strong Sauce
Jul 2, 2003

You know I am not really your father.





dereekb posted:

Thanks for the explanation! I understood closure but didn't realize it was scoped by function instead of the block as you said.

I actually managed to fix it by passing the website as a parameter into the bind function:

code:
...
			var deleteLink = copy.find('.delete-website');
			deleteLink.bind('click', website, function(event) {
				var website = event.data;
				removeWebsite(website);
				return false;
			});
...
Since that sets the scope properly, although I might rewrite it to fit your example since it'll be shorter.

On your example, is the (website) at the bottom a typo and supposed to be part of the comment?

code:

  function(website) {
...
  } //(website) <--- this is set as websites[i] from line #2

Thanks again!

That is an IIFE: Immediately Invoked Function Expression. You do that so the function you just created gets executed immediately.


quote:

Edit: When you say is "scoped by function", you mean the singleton that that function is created as? To me it means it ends up being the equivalent of a static function/class in Java where the website that is mentioned reads from what would be equivalent to static value; is that the case here, or am I wrong to think of functions as objects?
Most languages you use are block-scoped. Meaning that variables declared inside of, say, a for loop, are gone once they exit the for block.

Javascript is function-scoped, meaning any variables but variables declared get "hoisted" to the top of the function the variable is currently enclosed in.

I'm not sure about the 2nd part of your question, but functions are objects in javascript and you can create static members/functions, but there is no classical "class" type in javascript. So what you would do is:
code:
function PseudoClass() {
}
PseudoClass.staticProperty = "Hello"

s = new PseudoClass()
s.staticProperty // undefined
PseudoClass.staticProperty // "Hello"

Strong Sauce fucked around with this message at 08:59 on Jul 12, 2013

A MIRACLE
Sep 17, 2007

All right. It's Saturday night; I have no date, a two-liter bottle of Shasta and my all-Rush mix-tape... Let's rock.

So, it's been a while since I worked on my node project but I just tried to fire it up this morning to no avail. I'm not sure what is going on, it just doesn't run basically. Same problem with meteorite. Meteor works however.

Bash code:
alex@pit:~/meteorbook/microscope$ node
alex@pit:~/meteorbook/microscope$ mrt
alex@pit:~/meteorbook/microscope$ meteor
[[[[[ ~/meteorbook/microscope ]]]]]

=> Meteor server running on: [url]http://localhost:3000/[/url]

excidium
Oct 24, 2004

Tambahawk Soars
With node aren't you supposed to supply a JS file for it to run against?

Ex: node web.js

A MIRACLE
Sep 17, 2007

All right. It's Saturday night; I have no date, a two-liter bottle of Shasta and my all-Rush mix-tape... Let's rock.

excidium posted:

With node aren't you supposed to supply a JS file for it to run against?

Ex: node web.js

Yeah sorry, I was just posting that as an example. It's the same result either way though.

Mrs. Wynand
Nov 23, 2002

DLT 4EVA

A MIRACLE posted:

Yeah sorry, I was just posting that as an example. It's the same result either way though.

i wonder if it's a shell problem

does `node --version` work?

how about `which node`?

A MIRACLE
Sep 17, 2007

All right. It's Saturday night; I have no date, a two-liter bottle of Shasta and my all-Rush mix-tape... Let's rock.

Also what I suspect, but I'm not sure if it's like, a hardlinking issue or some other unixy nonsense that I don't fully understand.

Bash code:
alex@pit:~$ node --version
alex@pit:~$ which node
/usr/sbin/node
alex@pit:~$ ls -l /usr/sbin/node
-rwxr-xr-x 1 root root 60688 Nov 30  2009 /usr/sbin/node

Adbot
ADBOT LOVES YOU

Mrs. Wynand
Nov 23, 2002

DLT 4EVA
Well that ain't right. Reinstall node maybe?

I definitely had packaging issues with node both on ubuntu and osx so they are not uncommon.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply