Search Results

Search found 1405 results on 57 pages for 'prototype'.

Page 6/57 | < Previous Page | 2 3 4 5 6 7 8 9 10 11 12 13  | Next Page >

  • What's the point of the Prototype design pattern?

    - by user1905391
    So I'm learning about design patterns in school. Many of them are silly little ideas, but nevertheless solve some recurring problems(singleton, adapters, asynchronous polling, ect). But today I was told about the so called 'Prototype' design pattern. I must be missing something, because I don't see any benefits from it. I've seen people online say it's faster than using "new"' but this is doesn't make any sense, since at some point, regardless how the new object is created, memory needs to be allocated for it ect. Furthermore, doesn't this pattern run in the same circles as the 'chicken or egg' problem? By this I mean, since the prototype pattern essentially is just cloning objects, at some point the original object must be created itself (ie, not cloned). So this would mean, that I would need to have an existing copy of every object that I would ever want to clone already ready to clone? Seems stupid to me. Can anyone explain what the use of this pattern is? Original post: http://stackoverflow.com/questions/13887704/whats-the-point-of-the-prototype-design-pattern

    Read the article

  • Javascript: prototypeal inheritance and the prototype proprity

    - by JanD
    Hi, I have a simple code fragment in JS working with prototype inheritance. function object(o) { function F() {} F.prototype = o; return new F(); } //the following code block has a alternate version var mammal={ color: "brown", getColor: function(){ return this.color; } } var myCat = object(mammal); myCat.meow = function(){return "meow";} that worked fine but adding this: mammal.prototype.kindOf = "predator"; does not. ("mammal.prototype is undefined") Since I guessed that object maybe have no prototype I rewrote it, replacing the var mammal={... block with: function mammal(){ this.color="brown"; this.getColor = function(){return this.color;} } which gave me a bunch of other errors: "Function.prototype.toString called on incompatible object" and if I try to call _myCat.getColor() "myCat.getColor is not a function" Now I am totally confused. After reading Crockford, and Flanagan I did not get the solution for the errors. So it would be great if somebody knows... - why is the prototype undefined in the first example (which is foremost concern; I thought the prototype of explicitly set in the object() function) - why get I these strange errors trying to use the mammal function as prototype object in the object() function?

    Read the article

  • Javascript: prototypeal inheritance and the prototype property

    - by JanD
    Hi, I have a simple code fragment in JS working with prototype inheritance. function object(o) { function F() {} F.prototype = o; return new F(); } //the following code block has a alternate version var mammal = { color: "brown", getColor: function() { return this.color; } } var myCat = object(mammal); myCat.meow = function(){return "meow";} that worked fine but adding this: mammal.prototype.kindOf = "predator"; does not. ("mammal.prototype is undefined") Since I guessed that object maybe have no prototype I rewrote it, replacing the var mammal={... block with: function mammal() { this.color = "brown"; this.getColor = function() { return this.color; } } which gave me a bunch of other errors: "Function.prototype.toString called on incompatible object" and if I try to call _myCat.getColor() "myCat.getColor is not a function" Now I am totally confused. After reading Crockford, and Flanagan I did not get the solution for the errors. So it would be great if somebody knows... - why is the prototype undefined in the first example (which is foremost concern; I thought the prototype of explicitly set in the object() function) - why get I these strange errors trying to use the mammal function as prototype object in the object() function?

    Read the article

  • What is the point of the prototype method?

    - by Mild Fuzz
    I am reading through Javascript: The Good Parts, and struggled to get my head around the section on prototypes. After a little google, I came to the conclusion that it is to add properties to objects after the objects declaration. Using this script gleamed from w3schools, I noticed that removing the line adding the prototype property had no effect. So what is the point? //Prototyping function employee(name,jobtitle,born) { this.name=name; this.jobtitle=jobtitle; this.born=born; } var fred=new employee("Fred Flintstone","Caveman",1970); employee.prototype.salary=null; // <--- try removing this line fred.salary=20000; document.write(fred.salary);

    Read the article

  • Are there any prototype-based languages with a whole development cycle?

    - by Kaveh Shahbazian
    Are there any real-world prototype-based programming languages with a whole development cycle? "A whole development cycle" like Ruby and Python: web frameworks, scripting/interacting with the system, tools for debugging, profiling, etc. Thank you A brief note on PBPLs: (let's call these languages PBPL : prototype-based programming language) There are some PBPLs out there. Some are being widely used like JavaScript (which Node.js may bring it into the field - or may not!). One other language is ActionScript which is also a PBPL but tightly bound to Flash VM (is it correct to say so?). From less known ones I can speak of Lua which has a strong reputation in game development (mostly spread by WOW) but never took off as a full language. Lua has a table concept which can provide you some sort of prototype based programming facility. There is also JScript (Windows scripting tool) which is already pointless by the newcomer PowerShell (I have used JScript to manipulate IIS but I never understood what is JScript!). Others can be named like io (indeed very very neat, you will fall in love with it; absolutely impossible to use) and REBOL (What is this all about? A proprietary scripting tool? You must be kidding!) and newLISP (Which is actually a full language, but no one ever heard about it). For sure there are much more to list here but either I do not remember or I did not understood them as a real world thing, like Self).

    Read the article

  • Javascript inheritance: call super-constructor or use prototype chain?

    - by Jeremy S.
    Hi folks, quite recently I read about javascript call usage in MDC https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/call one linke of the example shown below, I still don't understand. Why are they using inheritance here like this Prod_dept.prototype = new Product(); is this necessary? Because there is a call to the super-constructor in Prod_dept() anyway, like this Product.call is this just out of common behaviour? When is it better to use call for the super-constructor or use the prototype chain? function Product(name, value){ this.name = name; if(value >= 1000) this.value = 999; else this.value = value; } function Prod_dept(name, value, dept){ this.dept = dept; Product.call(this, name, value); } Prod_dept.prototype = new Product(); // since 5 is less than 1000, value is set cheese = new Prod_dept("feta", 5, "food"); // since 5000 is above 1000, value will be 999 car = new Prod_dept("honda", 5000, "auto"); Thanks for making things clearer

    Read the article

  • How can I make an prototype ajax request with an array of values as a parameter?

    - by andresbravog
    i'm trying to make a ajax update in prototype with some values from a multirecordselect that sends a requests like. Parameters: {"action"=>"use_campaign", "campaigns"=> ["27929","27932"] , "advertiser_id"=>"", "controller"=>"admin/reporting", "ad_id"=>""} as you can see the request sends the "campaigns" elements as an array of values, i'm trying to do the same with this js code over prototype 7. // get the campaigns var campaign_ids = {}; var campaigns = $('filter_form').getInputs("hidden","report[campaigns][]"); campaigns.each( function(field) { campaign_ids.push(field.value); }); new Ajax.Updater('ad_filter', '/admin/reporting/use_campaign', { method : 'get', asynchronous : true, evalScripts : true, parameters : { 'advertiser_id' : $('filter_form')['report[advertiser_id]'].value, 'ad_id' : $('filter_form')['report[ad_id]'].value, 'campaigns' : campaign_ids } }); the campaigns_ids is getting the correct info as an array like: [ "27929", "27932" ] but seems that prototype ajax update is sending a request like: http://my_domain/admin/reporting/use_campaign?ad_id=&advertiser_id=&campaigns=27929&campaigns=27932 what sends parameters like: Parameters: {"action"=>"use_campaign", "campaigns"=> "27929" , "advertiser_id"=>"", "controller"=>"admin/reporting", "ad_id"=>""} I also tryed with Object.toJSON(campaign_ids) but i only get an escaped string like Parameters: {"action"=>"use_campaign", "campaigns"=>"[\"27929\",\"27932\"]" , "advertiser_id"=>"", "controller"=>"admin/reporting", "ad_id"=>""} There is anyway to do this as I wish? Thanks for all.

    Read the article

  • Prototype JS swallows errors in dom:loaded, and ajax callbacks?

    - by WishCow
    I can't figure out why prototype suppressess the error messages in the dom:loaded event, and in AJAX handlers. Given the following piece of HTML: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Conforming XHTML 1.1 Template</title> <script type="text/javascript" src="prototype.js"></script> <script type="text/javascript"> document.observe('dom:loaded', function() { console.log('domready'); console.log(idontexist); }); </script> </head> <body> </body> </html> The domready event fires, I see the log in the console, but there is no indication of any errors whatsoever. If you move the console.log(idontexist); line out of the handler, you get the idontexist is not defined error in the console. I find it a little weird, that in other event handlers, like 'click', you get the error message, it seems that it's only the dom:loaded that has this problem. The same goes for AJAX handlers: new Ajax.Request('/', { method: 'get', onComplete: function(r) { console.log('xhr complete'); alert(youwontseeme); } }); You won't see any errors. This is with prototype.js 1.6.1, and I can't find any indication of this behavior in the docs, nor a way to enable error reporting in these handlers. I have tried stepping through the code with FireBug's debugger, and it seems to jump to a function on line 53 named K, when it encounters the missing variable in the dom:loaded handler: K: function(x) { return x } But how? Why? When? I can't see any try/catch block there, how does the program flow end up there? I know that I can make the errors visible by packing my dom:ready handler(s) in try/catch blocks, but that's not a very comfortable option. Same goes for registering a global onException handler for the AJAX calls. Why does it even suppress the errors? Did someone encounter this before?

    Read the article

  • How to hide Amazon webstore default toolbar with Prototype?

    - by melaos
    Hi Guys, after playing around this morning, i've found that there's this default chunk of html code in the amazon webstore which will add a toolbar on top of the page. the html looks like below: <td id="wba_logo_bg"> <table class="logo" border="0" cellpadding="0" cellspacing="0" width="100%"> <tbody><tr><td align="left"></td> <td class="wba_account" style="padding: 5px;" align="right" valign="top"> <table border="0" cellpadding="0" cellspacing="0"> <form action="#" id="searchForm" method="get" name="searchForm"></form> <tbody><tr><td class="wba_account_link"> <a xmlns:xhtml="http://www.w3.org/1999/xhtml" class="myAccountNav" href="#" onclick="return false;">home</a></td> <td class="myAccountDots"></td> <td class="wba_account_link"><a class="myAccountNav" href="#" onclick="return false;">view cart</a></td> <td class="myAccountDots"></td><td class="wba_account_link"><a class="myAccountNav" href="#" onclick="return false;">my account</a></td> <td class="myAccountDots"></td><td class="wba_account_link"><a class="myAccountNav" href="#" onclick="return false;">order status</a></td> <td><img src="pageEditor_files/1_pixel.gif" hspace="7"></td> <td><input name="keyword" tabindex="1" type="text"></td> <td><img alt="Search" class="wba_search_btn" onclick="return false;" onkeyup="if (13==event.keyCode) searchForm.submit();" src="pageEditor_files/btn_search.gif" style="cursor: pointer;" tabindex="2" title="Search" hspace="3"> </td></tr></tbody> </table> </td></tr></tbody> </table> </td> and thus far i was able to use prototype to find those with the class name of wba_account_link and hide them via the codes below: function hideAmazonToolbar() { $("wba_logo_bg").hide(); }//end function but what i really want to do is preferably to hide the whole tbody instead, but with my limited prototype skills, i don't really know how to do this. can anybody point me to the right resources on how to get this done? thanks! EDIT Went higher up and apparently there's a td with an id, and solve it using prototype hide function! man, i love javascript framework :) thanks :)

    Read the article

  • Is there any Prototype Javascript function similar to Jquery Live to trace dynamic dom elements?

    - by Wbdvlpr
    Hi Event.observe(window,"load",function() { $$(".elem_classs").findAll(function(node){ return node.getAttribute('title'); }).each(function(node){ new Tooltip(node,node.title); node.removeAttribute("title"); }); }); Using above method, I can retrieve all elements having ".elem_class" and apply some javascript functions on them. But I have a modal/popup box which has some elements also having ".elem_class" and these dont get in the scope of findAll/each as they are loaded into the dom thru ajax. How do I apply the same to dynamically loaded elements as well? I am using Prototype Library. (I have used JQuery's Live function which keeps track of all future elements, but need to achieve something similar using Prototype) Thanks.

    Read the article

  • Ajax request with prototype - what is transport if not only responseText?

    - by Delirium tremens
    This is an example code from the prototype site. var url = '/proxy?url=' + encodeURIComponent('http://www.google.com/search?q=Prototype'); // notice the use of a proxy to circumvent the Same Origin Policy. new Ajax.Request(url, { method: 'get', onSuccess: function(transport) { var notice = $('notice'); if (transport.responseText.match(/href="http:\/\/prototypejs.org/)) notice.update('Yeah! You are in the Top 10!').setStyle({ background: '#dfd' }); else notice.update('Damn! You are beyond #10...').setStyle({ background: '#fdd' }); } }); The data that comes from the ajax request is available at transport.responseText, but what is transport if not only responseText?

    Read the article

  • Inheritance using prototype / "new"

    - by mikkol
    Hi I'm new in Javascript OO and want to know more about about inheritance. Hope you can provide some advice! I see this great post: How to "properly" create a custom object in JavaScript? which talks about how a class is inherited as I see in other websites, ex.: function man(x) { this.x = x; this.y = 2; } man.prototype.name = "man"; man.prototype.two = function() { this.y = "two"; } function shawn() { man.apply(this, arguments); }; shawn.prototype = new man; The above post claims that in order not to call "man"'s constructor while inheriting, one can use a helper like this instead: function subclassOf(base) { _subclassOf.prototype= base.prototype; return new _subclassOf(); } function _subclassOf() {}; shawn.prototype = subclassOf(man); While I understand its intention, I don't see why we can't call shawn.prototype = man.prototype; I see it works exactly the same. Or is there something I'm missing? Thanks in advance!

    Read the article

  • Self-Executing Anonymous Function vs Prototype

    - by Robotsushi
    In Javascript there are a few clearly prominent techniques for create and manage classes/namespaces in javascript. I am curious what situations warrant using one technique vs. the other. I want to pick one and stick with it moving forward. I write enterprise code that is maintained and shared across multiple teams, and I want to know what is the best practice when writing maintainable javascript ? I tend to prefer Self-Executing Anonymous Functions however I am curious what the community vote is on these techniques. Prototype : function obj() { } obj.prototype.test = function() { alert('Hello?'); }; var obj2 = new obj(); obj2.test(); Self-Closing Anonymous Function : //Self-Executing Anonymous Function (function( skillet, $, undefined ) { //Private Property var isHot = true; //Public Property skillet.ingredient = "Bacon Strips"; //Public Method skillet.fry = function() { var oliveOil; addItem( "\t\n Butter \n\t" ); addItem( oliveOil ); console.log( "Frying " + skillet.ingredient ); }; //Private Method function addItem( item ) { if ( item !== undefined ) { console.log( "Adding " + $.trim(item) ); } } }( window.skillet = window.skillet || {}, jQuery )); //Public Properties console.log( skillet.ingredient ); //Bacon Strips //Public Methods skillet.fry(); //Adding Butter & Fraying Bacon Strips //Adding a Public Property skillet.quantity = "12"; console.log( skillet.quantity ); //12 //Adding New Functionality to the Skillet (function( skillet, $, undefined ) { //Private Property var amountOfGrease = "1 Cup"; //Public Method skillet.toString = function() { console.log( skillet.quantity + " " + skillet.ingredient + " & " + amountOfGrease + " of Grease" ); console.log( isHot ? "Hot" : "Cold" ); }; }( window.skillet = window.skillet || {}, jQuery )); //end of skillet definition try { //12 Bacon Strips & 1 Cup of Grease skillet.toString(); //Throws Exception } catch( e ) { console.log( e.message ); //isHot is not defined } I feel that I should mention that the Self-Executing Anonymous Function is the pattern used by the jQuery team. Update When I asked this question I didn't truly see the importance of what I was trying to understand. The real issue at hand is whether or not to use new to create instances of your objects or to use patterns which do not require constructors of the use of the new keyword. I added my own answer, because in my opinion we should make use of patterns which don't use the new keyword. For more information please see my answer.

    Read the article

  • Microsoft présente Skype Translate, son prototype de traduction des conversations Skype quasiment en temps réel

    Microsoft présente Skype Translate, son prototype de traduction des conversations Skype quasiment en temps réel Microsoft a profité de la conférence Code qui se déroule actuellement à Rancho Palos Verdes (Californie) pour introduire une nouvelle fonctionnalité dans Skype permettant la traduction en un laps de temps d'une conversation dans la langue de l'interlocuteur. C'est d'ailleurs son PDG en personne, Satya Nadella, qui s'est chargé de la faire connaître durant la conférence. En guise de...

    Read the article

  • Prototype experience: Unity3D vs UDK

    - by LukeN
    Has anyone yet prototyped a game in both Unity3D and UDK? If so, which features made prototyping the game easier or more difficult in each toolkit? Was one prototype demonstrably better than the other (given the same starting assets)? I'm looking for specific answers with regard to using the toolkit features, not a comparison of available features. E.g. Destructable terrain is easier in toolkit X for reasons Y and Z. I can code, so the limitations of the inbuilt scripting languages are not a problem.

    Read the article

  • using JQuery and Prototype in the same page; more explanation needed!

    - by xenogen
    Hi everybody! I'm continuously having the problem when i use jquery lightbox (which runs prototype) and jquery news slider. I tried the "noconflict" method. The problem is I don't know the exact place to put the code. So, here, i'm putting my scripts within . So, please troubleshoot it and explain me where to put the patch. thank you very much. <head> <meta http-equiv="Content-Language" content="en-us"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Jquery</title> <script type="text/javascript" src="lb/js/prototype.js"></script> <script type="text/javascript" src="lb/js/scriptaculous.js?load=effects"></script> <script type="text/javascript" src="lb/js/lightbox.js"></script> <link href="lb/css/lightbox.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="news/jquery-1.2.3.pack.js"></script> <script type="text/javascript" src="news/jquery.easynews.js"></script> <style> html { background-color: #FFA928; font: normal 76% "Arial", "Lucida Grande",Verdana, Sans-Serif; color:black; } a { text-decoration: none; font-weight: bold; } .news_style{ display:none; } .news_show { background-color: white; color:black; width:350px; height:150px; font: normal 100% "Arial", "Lucida Grande",Verdana, Sans-Serif; overflow: auto; } .news_border { background-color: white; width:350px; height:150px; font: normal 100% "Arial", "Lucida Grande",Verdana, Sans-Serif; border: 1px solid gray; padding: 5px 5px 5px 5px; overflow: auto; } .news_mark{ background-color:white ; font: normal 70% "Arial", "Lucida Grande",Verdana, Sans-Serif; border: 0px solid gray; width:361px; height:35px; color:black; text-align:center; } .news_title{ font: bold 120% "Arial", "Lucida Grande",Verdana, Sans-Serif; border: 0px solid gray; padding: 5px 0px 9px 5px; color:black; } .news_show img{ margin-left: 5px; margin-right: 5px; } .buttondiv { position: absolute; /*float: left;*/ /*top: 169px;*/ padding: 5px 5px 5px 5px; background-color:white ; border: 1px solid gray; /*border-top-color: white;*/ border-top:none; height:20px; } </style> <script> $(document).ready(function(){ var newsoption1 = { firstname: "mynews", secondname: "showhere", thirdname:"news_display", fourthname:"news_button", newsspeed:'6000' } $.init_news(newsoption1); var myoffset=$('#news_button').offset(); var mytop=myoffset.top-1; $('#news_button').css({top:mytop}); }); </script> </head>

    Read the article

  • Why use object.prototype.constructor in OOP javascript?

    - by Matt
    I've recently started reading up on OOP javascript and one thing that authors seem to skip over is when an object A has been declared and suddenly I see "A.prototype.constructor =A; For example, var A = function(){}; // This is the constructor of "A" A.prototype.constructor = A; A.prototype.value = 1; A.prototype.test = function() { alert(this.value); } var a = new A(); // create an instance of A alert(a.value); // => 1 So I run the command in firebug "var A = function(){};" and then "A.Constructor" Which reveals it's a function. I understand this. I run the code "A.prototype.constructor = A;" and I thought this changes the A constructor from Function to A. The constructor property of A has been changed right? Instead when I run "A.constructor" it gives me function () still. What's the point? I also see A.constructor.prototype.constructor.prototype.. what is going on?

    Read the article

< Previous Page | 2 3 4 5 6 7 8 9 10 11 12 13  | Next Page >