Array.prototype.each = function (fn) {
this.map(fn)
}
This is my each function that works great in every other browser but IE. UGH! What am I doing wrong? the error points to the this in the function. Is it that IE doesn't like map? Has anyone seen this before? I thought my code was correct. Works perfect in FF, chrome and opera. the canvas text doesn't work in opera, but it does render the features so the each function is working.
I'll post the code if needed, but it's huge. here's the script running.[URL]..
According to ECMAScript, the root of the prototype chain is Object.Prototype. Each object has an internal property [[Prototype]] that could be another object or NULL.... However, it also says that every function has the Function prototype object: Function.Prototype, it confused me, because a function is an object, for a function object, what is its function prototype and object prototype..For example:
var x = function (n) {return n+1;};
what is the relationships of x, Object.Prototype and Function.Prototype
I am trying to get to the bottom of javascript object, prototypes etc. I have a fairly good grasp of it, but I get confused the closer I get to the base object.prototype. FIrst of all, I was under the impression that all objects descend directly from Object. But some objects (like Array) seem to inherit properties and methods from the function.prototype. So does this mean that the chain is like this:
object -- function -- array Second, I noticed (on the mozilla javascript reference site that object.prototype inherits properties and methods from function.prototype and vice versa!? How can this be? I must be missing something important about understanding the chain?
I am building a customised javascript prototype to sort an associative array on the array key (in ascending order). Basically, I am separating the array keys into a separate array and then using .sort() to sort the keys and then reassembling the original associative array elements according to the sorted keys array.
The sorting works ok except that when I run the test code below, the outputed sorted associative array has an extra element at the end of the array whose key is the name of the prototype function and the value for that element is the function code itself. Obviously I am misunderstanding something about associative arrays or how javascript prototypes work.
I'm having difficulty trying to return a multi-demensional array using Javascript Prototype's Hash Object.I have been able to return the values of the following associative php array using JSON and Javascript Prototype's Hash Object:
I am trying to use the sortBy function in the prototype.js library. Nevertheless, I can't work out what to include in the iterator function. Can someone shed some light on this?
I have a periodicalUpdater that returns countdown time that is created with php but I now need to call out one function when the time is right. the script PeriodicalUpdater calls
I'm learning how to use Javascripts and using Prototype framework by following a step by step tutorial from a book. Unfortunately when I stepping through the following code:[code]
Not sure if this is possible, but I have an external script that creates an object, and I want to overwrite some of its functionality, but keep the scope.
Here is a basic example:
Code: <script> Obj = function (userConfig) { this._init(userConfig);
[Code]....
I want it to log two Objects, but instead I get two window elements. Is this because I am declaring the functions in the global scope, and not from within the object?
Anyway I can keep the scope of the object, whilst still overwriting the function?
This JS code is on RoR+ImgMap site.I've tweak several portion of ImgMap, specifically around line 2205 of the file imgmap.js by adding code.so that when the user draws a shape, the focus will be set to the respective href field, instead of the default behavior - adding new row(imgmap form).
I need to know how to add an event to a button. The specific issue is that I want to add an event which is a prototype function of a class. Consider the following as an example:
I want to write a plugin, say 'myPlugin' which I can use like Code: $('#myID').myPlugin() ; $('#myID').myPlugin.test() ;
The plugin I wrote looks like Code: (function($){ $.fn.myPlugin = function() { // do something } $.fn.myPlugin.test = function() { var $this = $(this) ; // do something ; }})(jQuery) ;
This works and it doesn't work. It works because test() is called, but this is not the element with id '#myID' it is $.fn.myPlugin. To fix this I tried the following Code: (function($){ $.fn.myPlugin = function() { // do something } $.fn.myPlugin.prototype.test = function() { var $this = $(this) ; // do something ; }})(jQuery) ; but now the function 'test' is unknown.
is there a way in jQuery to bind variables to function calls similar as prototype.js does it? See [URL]
E.g. in the slideUp method of jQuery you can specify a callback that is called after the effect has finished. I would like to bind a variable to this call so that it is used inside of this callback as a closure.
It seems like determining element position in a web page is a difficult task. In the position reporting source code I've looked at there are special fixes for at least some versions of Safari and Opera. I am doing a lot of dragdrop experimentation and in some situations need a position reporting function. The function doesn't need to report the positions of exotic elements like images in button elements; however, I would like a position reporting function that can at least handle combinations of scrollable elements and tables....
I am trying to understand somecode. I don't think I am understanding everything correctly. Can someone confirm or add to my understanding?
Here is the code, below is my explanation:
- CODE 1 - is saying if the the class subnav_dd is called on an anchor tag on a li, then make the function in the if statement "live". (Live in a sense binds the function to the condition, but unlike bind it allows the condition to be used more then once. ) So if the class subnav_dd is the parent, and has a class of .dis then prevent anything below it from firing. CSS - If code 1 is true, then I will only get the first li to fire, the remaining ones will not.
- CODE 2 - This one is a little tricky. Function ToggleOptions takes 3 variables (target, array, state). The condition is if the div subnav + target have siblings, then check to see how many siblings are there. Put the amount of siblings into an array, then check the state of each sibling. I don't completely the rest of it.
I think if the div subnav is called and something is found in the array then the class dis is either added or removed. Then what? I don't understand why I still need the else that adds a class to #subnav_ +.target
In the below code, the alert message returns in one instance: 'someAnimal is [Mammal "Mr. Biggles"]' I don't understand how this is possible. We pass as an argument 'Mr. Biggles' to the Mammal constructor. Then assign it to the object name property. But then it ends there. There is a function called toString which will return the alert. But the toString function is not being called like this: alert('someAnimal is '+someAnimal.toString()); If it was like how it is above, it would make sense to me but now it makes no sense to me because I don't see where that toString() is being called - I only see that it is prototyped to the Mammal object.
Code: function Mammal(name){ this.name=name; this.offspring=[]; } Mammal.prototype.haveABaby=function(){ var newBaby=new Mammal("Baby "+this.name); this.offspring.push(newBaby); [Code]....
I have small problem and I am stuck with it for days without any solution. So I have a function that has an array,
function arrjoin( ) { var a = new Array (1,1,1,1,1,1,0,0,0,0); var c = a.join("~"); return (c); }
I have another function that call the arrjoin(). But before doing so, I get a value from an input field based on which i need to update the array in arrjoin() and save that as the new array(I mean same array but with the update value).
[Code]....
This is my current function. In this before I call joinarr( ) I need to update the array a in joinarr( ) with the value=index, that I am fetching here and save the array. (Haven't implemented yet) This process keeps on occurring every time a index value is generated. Thus in the next iteration the array a in arrjoin( ) show not be array show here but the array with the updates values. I am eventually transferring the array to server side to do some processing based on current value of the array.
I'm trying to pass titleArray and pointsArray to the task(); I'm getting an error mgs this.assignments() is not a function. I've highlighted this.assignments()
I am trying to put together a function that does the following; if a value is not in the array ..put it in, else if a value is already in the array...take it out. Something along the lines of the code below (but it doesn't work). Has anyone seen such a function or can see where I am going wrong? Code:
I am loading a set of icons using an array. The reason for this is that the icon set will be different depending on what some PHP code has given to the JavaScript.
My code currently looks like this.
Code:
var things_to_load = new Array(); things_to_load['header_cursors'] = new Array( 'default' , 'pointer' ); things_to_load['header_icons'] = new Array( '../img/triggers/to-roll/undo.png' , '../img/triggers/add.png' ); things_to_load['header_labels'] = new Array( 'undo' , 'add' );
[Code].....
The problem I have is that the click function gives the error "things_to_load.header_clicks[c] is not a function".
This makes sense as presumably the click function is saving the value and not what that value references.
how I can get this code to save the function not the string referencing it?
im trying to take an array and create a new array in a function to have it be used in the calculation function. I keep getting undefined when trying to output it. I can pass it directly using Spec(skills, spec, train); inside the function but that defeats the purpose of the function since its not always going to be used.
ive looked for hours on google and its all just variables which i can work fine but for this it will not work.
function Aluvian(){ document.ACCalculator.skillcredits.value = 100; var skills = new Array(); var spec = new Array();