Search Results

Search found 31578 results on 1264 pages for 'javascript functions'.

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

  • How important is graceful degradation of JavaScript? [closed]

    - by Stephen
    Should web developers continue to spend effort progressively enhancing our web applications with JavaScript, ensuring that features gracefully degrade, thereby ensuring accessibility? Or should we spend that time focused on new features or other areas of development? The subtext of that question would be: How many of our customers/clients/users utilize our websites or applications with JavaScript disabled? Do you have any projects with requirements that specifically demand JavaScript functionality (almost all of mine do), and do those requirements also demand graceful degradation? For the sake of asking this question, I pulled up programmers.stackexchange.com without JavaScript enabled, and I was greeted with this message: "Programmers - Stack Exchange works best with JavaScript enabled". It was difficult to log in, albeit the site seemed to generally work okay. (I wasn't able to vote up any questions.) I think this is a satisfactory approach to development. Imagine the effort involved in making all of the site's features work with plain old HTML and server-side logic. On the other hand, I wonder how many users have been alienated by this approach. We've all been trained (at least the good developers among us) to use progressive enhancement and to ensure our web applications' dynamic features degrade gracefully. Is this progressive enhancement just pissing into the wind, or do some of our customers actually utilize certain web services without JavaScript enabled?

    Read the article

  • Javascript: Machine Constants Applicable?

    - by DavidB2013
    I write numerical routines for students of science and engineering (although they are freely available for use by anybody else as well) and am wondering how to properly use machine constants in a JavaScript program, or if they are even applicable. For example, say I am writing a program in C++ that numerically computes the roots of the following equation: exp(-0.7x) + sin(3x) - 1.2x + 0.3546 = 0 A root-finding routine should be able to compute roots to within the machine epsilon. In C++, this value is specified by the language: DBL_EPSILON. C++ also specifies the smallest and largest values that can be held by a float or double variable. However, how does this convert to JavaScript? Since a Javascript program runs in a web browser, and I don't know what kind of computer will run the program, and JavaScript does not have corresponding predefined values for these quantities, how can I implement my own version of these constants so that my programs compute results to as much accuracy as allowed on the computer running the web browser? My first draft is to simply copy over the literal constants from C++: FLT_MIN: 1.17549435082229e-038 FLT_MAX: 3.40282346638529e+038 DBL_EPSILON: 2.2204460492503131e-16 I am also willing to write small code blocks that could compute these values for each machine on which the program is run. That way, a supercomputer might compute results to a higher accuracy than an old, low-level, PC. BUT, I don't know if such a routine would actually reach the computer, in which case, I would be wasting my time. Anybody here know how to compute and use (in Javascript) values that correspond to machine constants in a compiled language? Is it worth my time to write small programs in Javascript that compute DBL_EPSILON, FLT_MIN, FLT_MIN, etc. for use in numerical routines? Or am I better off simply assigning literal constants that come straight from C++ on a standard Windows PC?

    Read the article

  • A few questions about how JavaScript works

    - by KayoticSully
    I originally posted on Stack Overflow and was told I might get some better answers here. I have been looking deeply into JavaScript lately to fully understand the language and have a few nagging questions that I can not seem to find answers to (Specifically dealing with Object Oriented programming. I know JavaScript is meant to be used in an OOP manner I just want to understand it for the sake of completeness). Assuming the following code: function TestObject() { this.fA = function() { // do stuff } this.fB = testB; function testB() { // do stuff } } TestObject.prototype = { fC : function { // do stuff } } What is the difference between functions fA and fB? Do they behave exactly the same in scope and potential ability? Is it just convention or is one way technically better or proper? If there is only ever going to be one instance of an object at any given time, would adding a function to the prototype such as fC even be worthwhile? Is there any benefit to doing so? Is the prototype only really useful when dealing with many instances of an object or inheritance? And what is technically the "proper" way to add methods to the prototype the way I have above or calling TestObject.prototype.functionName = function(){} every time? I am looking to keep my JavaScript code as clean and readable as possible but am also very interested in what the proper conventions for Objects are in the language. I come from a Java and PHP background and am trying to not make any assumptions about how JavaScript works since I know it is very different being prototype based. Also are there any definitive JavaScript style guides or documentation about how JavaScript operates at a low level? Thanks!

    Read the article

  • Listening and firing events with Javascript and maybe jQuery

    - by at
    In my Javascript and Flex applications, users often perform actions that I want other Javascript code on the page to listen for. For example, if someone adds a friend. I want my Javascript app to then call something like triggerEvent("addedFriend", name);. Then any other code that was listening for the "addedFriend" event will get called along with the name. Is there a built-in Javascript mechanism for handling events? I'm ok with using jQuery for this too and I know jQuery makes extensive use of events. But with jQuery, it seems that its event mechanism is all based around elements. As I understand, you have to tie a custom event to an element. I guess I can do that to a dummy element, but my need has nothing to do with DOM elements on a webpage. Should I just implement this event mechanism myself?

    Read the article

  • Executing Javascript without a browser?

    - by Daniel
    I am looking into Javascript programming without a browser. I want to run scripts from the Linux or Mac OS X command line, much like we run any other scripting language (ruby, php, perl, python...) $ javascript my_javascript_code.js I looked into spider monkey (Mozilla) and v8 (Google), but both of these appear to be embedded. Is anyone using Javascript as a scripting language to be executed from the command line? If anyone is curious why I am looking into this, I've been poking around node.js

    Read the article

  • Should I be using a JavaScript SPA designed when security is important

    - by ryanzec
    I asked something kind of similar on stackoverflow with a particular piece of code however I want to try to ask this in a broader sense. So I have this web application that I have started to write in backbone using a Single Page Architecture (SPA) however I am starting to second guess myself because of security. Now we are not storing and sending credit card information or anything like that through this web application but we are storing sensitive information that people are uploading to us and will have the ability to re-download too. The obviously security concern that I have with JavaScript is that you can't trust anything that comes from JavaScript however in a Backbone SPA application, everything is being sent through JavaScript. There are two security features that I will have to build in JavaScript; permissions and authentication. The authentication piece is just me override the Backbone.Router.prototype.navigate method to check the fragment it is trying to load and if the JavaScript application.session.loggedIn is not set to true (and they are not viewing a none authenticated page), they are redirected to the login page automatically. The user could easily modify application.session.loggedIn to equal true (or modify Backbone.Router.prototype.navigate method) but then they would also have to not so easily dynamically embedded a link into the page (or modify a current one) that has the proper classes, data-* attributes, and href values to then load a page that should only be loaded when they user has logged in (and has the permissions). So I have an acl object that deals with the permissions stuff. All someone would have to do to view pages or parts of pages they should not be able to is to call acl.addPermission(resource, permission) with the proper permissions or modify the acl.hasPermission() to always return true and then navigate away and then back to the page. Now certain things is EMCAScript 5 like Object.seal() or Object.freeze() would help with some of this however we have to support IE 8 which does not support those pieces of functionality. Now the REST API also performs security checks on every request so technically even if they are able to see parts of the interface that they should not be able to, they still should not be able to actually affect any data. The main benefits for me in developing a JavaScript SPA application is that the application is a lot more responsive since it is only transferring the minimum amount of JSON data for the requested action and performing the minimum amount of work too. There are also other things that I think are beneficial like you are going to have to develop an API for the data (which is good if you want expand your application to different platforms/technologies) or their is more of a separation between front-end and back-end however if security is a concern, it is really wise to go down the road of a JavaScript SPA application for the front-end?

    Read the article

  • What can procs and lambdas do that functions can't in ruby

    - by SecurityGate
    I've been working in Ruby for the last couple weeks, and I've come to the subject of procs, lambdas and blocks. After reading a fair share of examples from a variety of sources, I don't how they're much different from small, specialized functions. It's entirely possible that the examples I've read aren't showing the power behind procs and lambdas. def zero_function(x) x = x.to_s if x.length == 1 return x = "0" + x else return x end end zero_lambda = lambda {|x| x = x.to_s if x.length == 1 return x = "0" + x else return x end } zero_proc = Proc.new {|x| x = x.to_s if x.length == 1 puts x = "0" + x else puts x end } puts zero_function(4) puts zero_lambda.call(3) zero_proc.call(2) This function, proc, and lambda do the exact same thing, just slightly different. Is there any reason to choose one over another?

    Read the article

  • Javascript in XSL that is loaded by Javascript

    - by James Armstead
    Is there anyway to have javascript run when a XSL sheet has been applied to an XML file by Javascript? I am using a JQuery plugin to apply the sheet to the xml but the javascript that is located inside of the XSL file will not run. I put the Javascript at the bottom of the file and it still does not run.. I can't seem to get an alert to even run?

    Read the article

  • detachEvent not working with named inline functions

    - by Polshgiant
    I ran into a problem in IE8 today (Note that I only need to support IE) that I can't seem to explain: detachEvent wouldn't work when using a named anonymous function handler. document.getElementById('iframeid').attachEvent("onreadystatechange", function onIframeReadyStateChange() { if (event.srcElement.readyState != "complete") { return; } event.srcElement.detachEvent("onreadystatechange", onIframeReadyStateChange); // code here was running every time my iframe's readyState // changed to "complete" instead of only the first time }); I eventually figured out that changing onIframeReadyStateChange to use arguments.callee (which I normally avoid) instead solved the issue: document.getElementById('iframeid').attachEvent("onreadystatechange", function () { if (event.srcElement.readyState != "complete") { return; } event.srcElement.detachEvent("onreadystatechange", arguments.callee); // code here now runs only once no matter how many times the // iframe's readyState changes to "complete" }); What gives?! Shouldn't the first snippet work fine?

    Read the article

  • using javascript onchange to fill a calendar

    - by scatman
    i have a calendar and a textbox in my c# asp.net application. when a user enters a date in the textbox, the selected date in the calendar should become the date entered in the text box. the hard part is that i need to do this in javascript. what i have now is this: <asp:TextBox ID="txtDate" runat="server" onchange="javascript: Changed( this );" /> <asp:Calendar ID="calDate" runat="server" /> <script type="text/javascript"> var calendarID = ''; function Changed(textControl) { var date = Date.parse(textControl.value); //this is giving me the date in seconds var cal = document.getElementById(calendarID); } </script> and i am setting calendarID in this way: <script type="text/javascript"> calendarID = "<%=calDate.ClientID%>"; </script> there is no cal.selectedDate or anything like this... any help?

    Read the article

  • detachEvent not working with named anonymous functions

    - by Polshgiant
    I ran into a problem in IE8 today (Note that I only need to support IE) that I can't seem to explain: detachEvent wouldn't work when using a named anonymous function handler. document.getElementById('iframeid').attachEvent("onreadystatechange", function onIframeReadyStateChange() { if (event.srcElement.readyState != "complete") { return; } event.srcElement.detachEvent("onreadystatechange", onIframeReadyStateChange); // code here was running every time my iframe's readyState // changed to "complete" instead of only the first time }); I eventually figured out that changing onIframeReadyStateChange to use arguments.callee (which I normally avoid) instead solved the issue: document.getElementById('iframeid').attachEvent("onreadystatechange", function () { if (event.srcElement.readyState != "complete") { return; } event.srcElement.detachEvent("onreadystatechange", arguments.callee); // code here now runs only once no matter how many times the // iframe's readyState changes to "complete" }); What gives?! Shouldn't the first snippet work fine?

    Read the article

  • CoffeeScript Class Properties Within Nested Anonymous Functions

    - by Aric
    I'm just taking a look at CoffeeScript for the first time so bare with me if this is a dumb question. I'm familiar with the hidden pattern methodology however I'm still wrapping my head around object prototypes. I'm trying to create a basic class for controlling a section on my site. The problem I'm running into is losing defined class variables within a different scope. For example, the code below works fine and creates the properties within the object perfectly. However when I jump into a jQuery callback I lose all knowledge of the class variables storing some of the jQuery objects for multiple uses. Is there a way to grab them from within the callback function? class Session initBinds: -> @loginForm.bind 'ajax:success', (data, status, xhr) -> console.log("processed") return @loginForm.bind 'ajax:before', (xhr, settings) -> console.log @loader // need access to Session.loader return return init: -> @loginForm = $("form#login-form") @loader = $("img#login-loader") this.initBinds() return

    Read the article

  • How to combine these two JavaScript functions?

    - by user289346
    var curtext = "View large image"; function changeSrc() { if (curtext == "View large image") { document.getElementById("boldStuff").innerHTML = "View small image"; curtext="View small image"; } else { document.getElementById("boldStuff").innerHTML = "View large image"; curtext = "View large image"; } } var curimage = "cottage_small.jpg"; function changeSrc() { if (curimage == "cottage_small.jpg") { document.getElementById("myImage").src = "cottage_large.jpg"; curimage = "cottage_large.jpg"; } else { document.getElementById("myImage").src = "cottage_small.jpg"; curimage = "cottage_small.jpg"; } } </script> </head> <body> <!-- Your page here --> <h1> Pink Knoll Properties</h1> <h2> Single Family Homes</h2> <p> Cottage:<strong>$149,000</strong><br/> 2 bed, 1 bath, 1,189 square feet, 1.11 acres <br/><br/> <a href="#" onclick="changeSrc()"><b id="boldStuff" />View large image</a></p> <p><img id="myImage" src="cottage_small.jpg" alt="Photo of a cottage" /></p> </body> I need help, how to put as one function with two arguments? That means when you click, the image and text both will be change. Thank you! Bianca

    Read the article

  • Calling javascript class within other Js

    - by harigm
    I have Aptana plugin in eclipse, I have a javascript (one.js) and i have included one more Javscript(two.js) within one.js. I click on any functions within one.js and if those functions exists in the same one.js, the control is going to the respective function. Suppose if the function exists in two.js, the control is not going to two.js Can any one help me with this?

    Read the article

  • Javascript clears a variable after there is no further reference it

    - by Praveen Prasad
    It is said, javascript clears a variable from memory after its being referenced last. just for the sake of this question i created a JS file with only one variable; //file start //variable defined var a=["Hello"] //refenence to that variable alert(a[0]); // //file end no further reference to that variable, so i expect javascript to clear varaible 'a' Now i just ran this page and then opened firebug and ran this code alert(a[0]); Now this alerts the value of variable, If the statement "Javascript clears a variable after there is no further reference it" is true how come alert() shows its value. Is it because all variable defined in global context become properties of window object, and since even after the execution file window objects exist so does it properties.

    Read the article

  • JavaScript Data Binding Frameworks

    - by dwahlin
    Data binding is where it’s at now days when it comes to building client-centric Web applications. Developers experienced with desktop frameworks like WPF or web frameworks like ASP.NET, Silverlight, or others are used to being able to take model objects containing data and bind them to UI controls quickly and easily. When moving to client-side Web development the data binding story hasn’t been great since neither HTML nor JavaScript natively support data binding. This means that you have to write code to place data in a control and write code to extract it. Although it’s certainly feasible to do it from scratch (many of us have done it this way for years), it’s definitely tedious and not exactly the best solution when it comes to maintenance and re-use. Over the last few years several different script libraries have been released to simply the process of binding data to HTML controls. In fact, the subject of data binding is becoming so popular that it seems like a new script library is being released nearly every week. Many of the libraries provide MVC/MVVM pattern support in client-side JavaScript apps and some even integrate directly with server frameworks like Node.js. Here’s a quick list of a few of the available libraries that support data binding (if you like any others please add a comment and I’ll try to keep the list updated): AngularJS MVC framework for data binding (although closely follows the MVVM pattern). Backbone.js MVC framework with support for models, key/value binding, custom events, and more. Derby Provides a real-time environment that runs in the browser an in Node.js. The library supports data binding and templates. Ember Provides support for templates that automatically update as data changes. JsViews Data binding framework that provides “interactive data-driven views built on top of JsRender templates”. jQXB Expression Binder Lightweight jQuery plugin that supports bi-directional data binding support. KnockoutJS MVVM framework with robust support for data binding. For an excellent look at using KnockoutJS check out John Papa’s course on Pluralsight. Meteor End to end framework that uses Node.js on the server and provides support for data binding on  the client. Simpli5 JavaScript framework that provides support for two-way data binding. WinRT with HTML5/JavaScript If you’re building Windows 8 applications using HTML5 and JavaScript there’s built-in support for data binding in the WinJS library.   I won’t have time to write about each of these frameworks, but in the next post I’m going to talk about my (current) favorite when it comes to client-side JavaScript data binding libraries which is AngularJS. AngularJS provides an extremely clean way – in my opinion - to extend HTML syntax to support data binding while keeping model objects (the objects that hold the data) free from custom framework method calls or other weirdness. While I’m writing up the next post, feel free to visit the AngularJS developer guide if you’d like additional details about the API and want to get started using it.

    Read the article

  • What should JavaScript be renamed to [closed]

    - by Evan Plaice
    Background: I have been watching Douglas Crockford's series of presentation about JavaScript History (which I highly recommend) lately and a one comment of his specifically piqued my attention. The trademark for 'JavaScript' is owned by Oracle History: Due to time constraints at Netscape, the language was literally written in weeks and released in very buggy form. To make it seem more appealing, Netscape picked JavaScript to appeal to the massively growing population of Java developers. Unfortunately, this pissed off Sun and stirred up a lot of controversy between the two organizations. At some point, they came to an agreement whereby Netscape was given permission to use the name as long as Sun owned the trademark. Some people incorrectly refer to JavaScript as ECMAScript because that's where the standard for the language is registered but, aside from it's current marketing-driven label, it doesn't really have a name. Fast Forward Sun goes down only to be swallowed by Oracle, who has no reservations about litigating for profit, now owns the name. So... If Oracle decides and forces JavaScript to take on a new name, what name would best represent the language?

    Read the article

  • Performance: recursion vs. iteration in Javascript

    - by mastazi
    I have read recently some articles (e.g. http://dailyjs.com/2012/09/14/functional-programming/) about the functional aspects of Javascript and the relationship between Scheme and Javascript (the latter was influenced by the first, which is a functional language, while the O-O aspects are inherited from Self which is a prototyping-based language). However my question is more specific: I was wondering if there are metrics about the performance of recursion vs. iteration in Javascript. I know that in some languages (where by design iteration performs better) the difference is minimal because the interpreter / compiler converts recursion into iteration, however I guess that probably this is not the case of Javascript since it is, at least partially, a functional language.

    Read the article

  • How to use html and JavaScript in Content Editor web part in SharePoint2010

    - by ybbest
    Here are the steps you need to take to use html and JavaScript in content editor web part. 1. Edit a site page and add a content editor web part on the page. 2. After the content editor is added to the page, it will display on the page like shown below 3. Next, upload your html and JavaScript content as a text file to a document library inside your SharePoint site. Here is the content in the document <script type="text/javascript"> alert("Hello World"); </script> 4. Edit the content editor web part and reference the file you just uploaded. 5. Save the page and you will see the hello world prompt. References: http://stackoverflow.com/questions/5020573/sharepoint-2010-content-editor-web-part-duplicating-entries http://sharepointadam.com/2010/08/31/insert-javascript-into-a-content-editor-web-part-cewp/

    Read the article

  • data handling with javascript

    - by Vincent Warmerdam
    Python has a very neat package called pandas which allows for quick data transformation; tables, aggregation, that sort of thing. A lot of these types of functionality can also be found in the python itertools module. The plyR package in R is also very similar. Usually one woud use this functionality to produce a table which is later visualized with a plot. I am personally very fond of d3, and I would like to allow the user to first indicate what type of data aggregation he wants on the dataset before it is visualized. The visualisation in question involves making a heatmap where the user gets to select the size of the bins of the heatmap beforehand (I want d3 to project this through leaflet). I want to visually select the ideal size of the bins for the heatmap. The way I work now is that I take the dataset, aggregate it with python and then manually load it in d3. This is a process that takes a lot of human effort and I was wondering if the data aggregation can be done through the javascript of the browser. I couldn't find a package for javascript specifically built for data, suggesting (to me) that this is a bad idea and that one should not use javascript for the data handling. Is there a good module/package for javascript to handle data aggregation? Is it a good/bad idea to do the data aggregation in javascript (performance wise)?

    Read the article

  • Extending Currying: Partial Functions in Javascript

    - by kerry
    Last week I posted about function currying in javascript.  This week I am taking it a step further by adding the ability to call partial functions. Suppose we have a graphing application that will pull data via Ajax and perform some calculation to update a graph.  Using a method with the signature ‘updateGraph(id,value)’. To do this, we have do something like this: 1: for(var i=0;i<objects.length;i++) { 2: Ajax.request('/some/data',{id:objects[i].id},function(json) { 3: updateGraph(json.id, json.value); 4: } 5: } This works fine.  But, using this method we need to return the id in the json response from the server.  This works fine, but is not that elegant and increase network traffic. Using partial function currying we can bind the id parameter and add the second parameter later (when returning from the asynchronous call).  To do this, we will need the updated curry method.  I have added support for sending additional parameters at runtime for curried methods. 1: Function.prototype.curry = function(scope) { 2: scope = scope || window 3: var args = []; 4: for (var i=1, len = arguments.length; i < len; ++i) { 5: args.push(arguments[i]); 6: } 7: var m = this; 8: return function() { 9: for (var i=0, len = arguments.length; i < len; ++i) { 10: args.push(arguments[i]); 11: } 12: return m.apply(scope, args); 13: }; 14: } To partially curry this method we will call the curry method with the id parameter, then the request will callback on it with just the value.  Any additional parameters are appended to the method call. 1: for(var i=0;i<objects.length;i++) { 2: var id=objects[i].id; 3: Ajax.request('/some/data',{id: id}, updateGraph.curry(id)); 4: } As you can see, partial currying gives is a very useful tool and this simple method should be a part of every developer’s toolbox.

    Read the article

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