Hey guys,
A JavaScript newbie here. I have this following code:
function testObject(elem) {
this.test = "hi";
this.val = elem;
console.log(this.test+this.val);
echo();
function echo () {
console.log(this.test+this.val);
}
}
var obj = new testObject("hello");
When it is run, I expect "hihello" to be ...
I'd like to wrap Prototype Ajax.Request in order to simulate AJAX latency. I mean, using a closure and Prototype's delay() facility, but apparently there is something wrong with my code
/*
* Purpose: simulate AJAX latency when developing on localhost
* What's wrong?
*/
Ajax.Request = (function(original) {
return function(url, optio...
Some people say that every programming language has its "complexity budget" which it can use to accomplish its purpose. But if the complexity budget is depleted, every minor change becomes increasingly complicated and hard to implement in a backward-compatible way.
After reading the current provisional syntax for Lambda (≙ Lambda expres...
I have some working Javascript that manipulates the some DOM elements. The problem is, I don't understand why it works, which is never a good thing. I am trying to learn more about object oriented javascript and javascript best practices, so the organization may seems a little strange.
Basically, I wrap two methods that manipulate the ...
I have an associative array of objects that I want to extend with a number of functions.
myCtrls //Array of objects
I do this with the following loop
$(document).ready(function() {
for (ctrlName in fieldCtrls){
var ctrl = fieldCtrls[ctrlName];
ctrl.Initialize = function(){
//Do some stuff
...
My understanding of closures is that they are essentially a function which uses a variable that you would assume would be out of scope. I guess heres an example I saw the other day:
function closureMaker(somearg)
{
var local_value = 7;
function funcToReturn(arg1, arg2)
{
return local_value + somearg + arg1 + arg2;
...
I have a piece of code that filters a list using LINQ, creates a list of instances of an anonymous type, and assigns an event handler to each instance:
// Select every linear expression and create a menu item from it
var items = from expr in expressionList.Expressions
where expr.Type == ExpressionType.Linear
let ...
Hi,
I have following structure for my client;
var myObject = (function(){
var mainObjectList = [];
var globalObject = {
init:function(mainObjectId){
var logger = {};
var utilityObject1 = {};
var utilityObject2 = {};
var mainObject = {};
m...
I have some Google Maps JS that plots a number of markers on a map. However, when loading the markers I noticed that the images were not loading in time and so the markers were not being placed.
To get around this I modified my function that returned a map marker as follows:
function newGoogleMapPin(type){
var imgpath = "img/gmapico...
class C
end
var = "I am a local var outside"
C.class_eval do
def self.a_class_method
puts var
end
# I know, this is not correct, because the 'def' created a new scope;
# I am asking a solution to make it;
# I also know that use 'define_method' can create a instance method without creating a new scope.
# but my...
I have a Google Map, and I am adding event listeners to different things. For instance, I have a Point object, and for this object, I have been adding events as thus:
google.maps.event.addListener(this.marker, 'click', (function(point) {
return function(event) {
alert(point.index);
}})(this));
I have a lot of these ev...
In thinking about blocks, I've always wondered why the
thingers.each { |thing|
example is actually interesting (since there's another, built-in way to do it). In most modern languages there's a way to iterate through a collection and apply some inline code to it. But then I thought that maybe the for (Thing thing : things) { syntax is...
Hi
I'm trying to pass a parameter in the onclick event. Below is a sample code:
<div id="div"></div>
<script language="javascript" type="text/javascript">
var div = document.getElementById('div');
for (var i = 0; i < 10; i++) {
var link = document.createElement('a');
link.setAttribute('href', '#');
link.inn...
I'm using the JQuery getJSON function to get some JSON-formatted data.
The data will be used along with the YouTube JavaScript API: http://code.google.com/apis/youtube/js_api_reference.html
The JSON data is not pulled from YouTube. It's a simple, hand-written list of YouTube Video ID's and Titles which are listed on a CSV. I'm using PH...
In terms of runtime, what is the best known transitive closure algorithm for directed graphs?
I am currently using Warshall's algorithm but its O(n^3). Although, due to the graph representation my implementation does slightly better (instead of checking all edges, it only checks all out going edges). Is there any transitive closure algo...
Ok, I don't know how to actually ask this question without showing it. (Also explains why I can't figure out how to search for it on Google.)
Given the following like of code:
dijit.byId('leftNavigationPane').onLoad = function(){setSecondaryNav(url.secondaryNavId);};
I want the variable url.secondaryNavId to be evaluated, so what I ...
I am trying to run the following code:
I pass parameter to a function, but it always has the value of the last object run through the loop. I read some articles about it on stackoverflow, but I couldn't find out how to make it run in my solution.
The object is a JSON object returned from the server. All it's values are correct.
for(v...
I am wondering if it is possible to create a closure in ActionScript2 like it is possible in Javascript.
This doesn't work:
var util = function(){
var init = function(){
trace(this + ': util'); // i want to know this thing works!
var myUtils = new MyAS2Utils(); // load some stuff
var url = myUtils.getURLInSomeReall...
As a followup to http://stackoverflow.com/questions/3558240 I'm now having troubles with defining setters in a loop.
This is the code that I'm attempting to use within a Greasemonkey script.
var setValue_InStoredObject = function(_prefName, _varName, _newValue)
{
console.info('setValue_InStoredObject:\narguments = ');
console.inf...
I have a Javascript "class" defined like so:
var Welcomer = function(name) {
var pName = name;
var pMessage = function() {
return "Hi, " + pName + "!";
};
return {
sayHi: function() {
alert(pMessage());
}
};
};
new Welcomer('Sue').sayHi();
Is there a way to "subclass" Welcomer in such a way that I can red...