What's The Difference Between SomeFunc.blah = Function(){} And SomeFunc.prototype.blah = Function(){}?

Dec 21, 2006

My query is very straight forward (I think).

What's the difference between

someFunc.blah = function(){ ; }

and

someFunc.prototype.blah = function(){ ; }

?Does someFunc.blah call upon someFunc.prototype.blah?

Is there any difference?

View 5 Replies


ADVERTISEMENT

Difference Between Object.prototype And Function.prototype?

Nov 25, 2011

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

View 5 Replies View Related

Whats Wrong With This Wait Function?

Jul 20, 2005

I have tried to write a wait function but it seems like it will not brake the while loop. I tried two different solutions. Can anyone tell me what I am doing wrong, and come with another suggestion? If I call the function like this: wait(500); it should wait 500ms right?

function wait(time) {
while(1){
setTimeout("break;",time);
}
}

function wait(time) {
var flag=0;
while(flag=0){
setTimeout("flag=1;",time);
}
}

View 2 Replies View Related

OnClick="function - Whats The Value Of The Anchor Tag Just Clicked

Oct 23, 2010

I need to get the object that was just clicked, to insert into a JavaScript function. I've tried "function('this')" and similar things, but it doesn't work.

View 3 Replies View Related

Difference Between A Function Pointer And A Function Call?

Mar 11, 2011

I'm working through the sitepoint ajax book and had a problem with a particular chunk of code. I eventually tracked down the error and it was being caused because I had:

window.onload = Monitor.init();
instead of:
window.onload = Monitor.init;

Now, one of the sticky threads mentioned that the first is a function call and the second is a function pointer. My questions are:What's the difference between a function call and a function pointer? Why did it cause problems in this particular case? What are the general implications/issues with using one over the other?

View 1 Replies View Related

How Come Object.prototype Inherits From Function.prototype

Dec 14, 2009

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?

View 24 Replies View Related

JQuery :: Difference Between (function($) { /* Code */ }); And $(document).ready(function(){ /* Code */ });?

Jul 22, 2010

(function($) { /* code*/ })(jQuery);
$
(
document

[code]....

I know that document.read is loaded when html page is been loaded. But what's the difference between the two?

View 1 Replies View Related

JQuery :: Bind Variables To A Function Call (like In Prototype.js Function#bind)

Nov 4, 2010

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.

View 2 Replies View Related

Js Function To Find The Difference Between Two Dates?

Apr 5, 2011

i've written a js function to find the difference between two dates. the format being used is dd/mm/yyyy hh:mm. The function returns correct value when give one set of values, but go wrong with another set. examples are given below.

set 1 : Time 1 = 24/02/2011 09:30 , time 2 = 24/02/2011 16:00

Output is corret here. It gives 6 Hours & 30 Minutes (after converting the difference)

set 2: Time 1 = 24/02/2011 09:30 , time 2 = 25/02/2011 16:00

Here, it gives 31 days, 6 Hours & 30 Minutes. My code is given below. Also the alert of dates display strange values. Don't know if it is timezone issue.

function compareDateTime(frmtime,totime)
{
var date1 = new Date(frmtime);
var date2 = new Date(totime);[code]......

View 5 Replies View Related

Difference Between Declaring Var Inside Function And Outside?

Aug 21, 2010

I worked on a simple image slide-show with javascript, and I assigned a value to a var outside of a function using getElementById() like this:

Code:
window.onload = initLinks;
myImg = new Array("images/img01.jpg","images/img02.jpg","images/img03.jpg","images/img04.jpg");
curPic = 0;[code]..........

View 2 Replies View Related

Difference Between Ways For Declaring A Function?

Jul 30, 2010

is there any real difference between these two function declarations?

function DoSomething(parm) {
//do something here
}[code]...........

View 2 Replies View Related

SortBy Function In Prototype.js

Feb 27, 2006

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?

View 3 Replies View Related

IE And Array.prototype Function?

May 5, 2010

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]..

View 2 Replies View Related

Array.prototype.push = Function() {

May 7, 2007

I found this code on Internet:

<script type="text/javascript">

Array.prototype.push = function() {
var n = this.length >>> 0;
for (var i = 0; i < arguments.length; i++) {
this[n] = arguments[i];
n = n + 1 >>> 0;
}
this.length = n;
return n;
};

</script>

Question 1: How to call this function?
Question 2: When I delete >>> 0, what I lose? ( >>>0 &#305; sildi&#287;im zaman, ne kaybederim?)

View 4 Replies View Related

Prototype PeriodicalUpdater Getting Function From ResponseText

Jun 2, 2009

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

[Code]...

View 1 Replies View Related

JQuery :: Equivalent Of Prototype Function.bind?

Jan 5, 2010

Is there a jQuery way of doing this Prototype bind?

var func = myFunction;
setTimeout
func.bind
this
, 1000
;

View 2 Replies View Related

Using Prototype Framework With Hide And Show Function

Mar 22, 2010

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]

View 8 Replies View Related

Overwriting A Prototype Function And Keeping Scope?

Nov 3, 2010

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?

View 2 Replies View Related

Prototype Focus Function Not Working Without Alert

Apr 19, 2010

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).

View 4 Replies View Related

JQuery :: Adding Prototype Function As An Event Handler?

Aug 30, 2010

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:

MyTestClass = function() {
this.firstName = "Pete";
this.lastName = "Johnson";

[code]....

View 2 Replies View Related

JQuery :: Plugin - Function (Prototype) Test Unknown

Jan 8, 2010

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.

View 6 Replies View Related

Setting A Constructor's Prototype Property To A Primative, Array Or Function.

Oct 30, 2006

What happens if you do this?

function Person() {}
Person.prototype = 7;
var ted = new Person();

Also what happens if you set Person.prototype to an array or function?

View 1 Replies View Related

Position Reporting Function: Flanagan, Yahoo!, Kruze, Prototype ... All Broken At Least A Little.

Oct 9, 2006

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....

View 2 Replies View Related

Calling A Function With Prototype Property - Alert Message Returns In One Instance: 'someAnimal Is [Mammal "Mr. Biggles"]'

Jun 12, 2010

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]....

View 2 Replies View Related

Function Calls Another Function But Second Function Is Never Called?

Dec 8, 2009

I have some javascript the works in conjunction with a flash video player. When a user selects a video in the Flash video list and new video is called and begins to play. Also, when that video is selected a function called "doOnMediaLoad()" is called and inside of that function I have put a call to another function that I wrote in the same script.function that is called when user selects flash player video list.

function doOnMediaLoad(e) {
vcomments_changed(e.id); //call to my function
}

[code]....

View 2 Replies View Related

Function Calls Another Function But Second Function Is Never Called

Dec 9, 2009

I have some javascript the works in conjunction with a flash video player. When a user selects a video in the Flash video list and new video is called and begins to play. Also, when that video is selected a function called "doOnMediaLoad()" is called and inside of that function I have put a call to another function that I wrote in the same script.

[Code]...

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved