Search Results

Search found 3096 results on 124 pages for 'scope creep'.

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

  • Scope of object properties & methods

    - by Anish
    In the article Show love to the object literal, it's said: When we have several scripts in a page, the global variables & functions will get overwritten if their name repeats. One solution is to make the variables as properties & functions as methods of an object, and access them via the object name. But will this prevent the issue of variables getting into the global namespace? <script> var movie = { name: "a", trailer: function(){ //code } }; </script> In the above code which elements gets added to the global namespace? a) Just the object name - movie b) Object name as well as the properties and methods inside it – movie, movie.name, movie.trailer()

    Read the article

  • javascript scope problem when lambda function refers to a variable in enclosing loop

    - by Stefan Blixt
    First question on stackoverflow :) Hope I won't embarrass myself... I have a javascript function that loads a list of albums and then it creates a list item for each album. The list item should be clickable, so I call jQuery's click() with a function that does stuff. I do this in a loop. My problem is that all items seem to get the same click function, even though I try to make a new one that does different stuff in each iteration. Another possibility is that the iteration variable is global somehow, and the function refers to it. Code below. debug() is just an encapsulation of Firebug's console.debug(). function processAlbumList(data, c) { for (var album in data) { var newAlbum = $('<li class="albumLoader">' + data[album].title + '</li>').clone(); var clickAlbum = function() { debug("contents: " + album); }; debug("Album: " + album + "/" + data[album].title); $('.albumlist').append(newAlbum); $(newAlbum).click(clickAlbum); } } Here is a transcript of what it prints when the above function runs, after that are some debug lines caused by me clicking on different items. It always prints "10", which is the last value that the album variable takes (there are 10 albums). Album: 0/Live on radio.electro-music.com Album: 1/Doodles Album: 2/Misc Stuff Album: 3/Drawer Collection Album: 4/Misc Electronic Stuff Album: 5/Odds & Ends Album: 6/Tumbler Album: 7/Bakelit 32 Album: 8/Film Album: 9/Bakelit Album: 10/Slow Zoom/Atomic Heart contents: 10 contents: 10 contents: 10 contents: 10 contents: 10 Any ideas? Driving me up the wall, this is. :) /Stefan

    Read the article

  • jquery scope issue

    - by matthewb
    I am having issue with the following: I can't seem to keep the link I am selecting in each repeated item. The word "this" is getting lost. the Var event_id works for each element, but the var $something is undefined? Why is that, Ideally I wanted to do a switch statement but same issue, can't seem to get it to know what link I click and the elements around it to do the action. Updated Full Function: function rsvp (selector,function_url) { $(selector).livequery('click',function(){ var $select = $(selector).attr('rel'); var $event_id= $(this).parents('ul.event-options').attr('rel'); if ($select == "attending") { $(this).closest('span.rsvp-status').html("I'm Attending &ndash; <a href='javascript:;' class='remove' rel='remove'>Remove</a>"); var $something = $(this).parents('ul.event-options').attr('rel'); alert($something); } if ($select == "remove") { $(this).closest('span.rsvp-status').html("Not Attending &ndash; <a href='javascript:;' class='rsvp' rel='attending'>RSVP?</a>"); } if ($select == "interested") { $(this).closest('li').addClass('interested'); $(this).closest('li').removeClass('not-interested'); $(this).closest('li').html("You're Interested"); } $.ajax({ type: "POST", url: "/events/set_member/"+function_url, data: "event_id="+$event_id, beforeSend: function() { $("<span class='notice'>Updating...</span>").prependTo('body'); }, complete: function() { $('span.notice').fadeOut(500); } }); }); } rsvp ('a.rsvp','rsvp'); rsvp ('a.interests','interested'); rsvp ('a.remove','remove'); HTML <ul class="event-options" rel="<?=$event['event_id']?>"> <?php if($event['rsvp_total'] > 0) { ?> <!-- Show Only When Count is Greater than 0 --> <li class="group"><span class="total"><?= $event['rsvp_total']?></span>Interested </li> <?php } ?> <li class="rsvp"><span class="rsvp-status"> Not Attending &ndash; <a href="javascript:;" class="rsvp" rel="attending">RSVP?</a></span></li> <li class="not-interested"> <a href="javascript:;" class="interests" rel="interested"> Interested? </a> </li> <li class="place"><span><a href="<?=$place_path.$event['place_id']?>"><?=$event['place_name']?></a></span></li> <li class="share" rel="<?=$event['event_name']?>"> <a class="sharethis"></a> </li> </ul>

    Read the article

  • Scope of "library" methods

    - by JS
    Hello, I'm apparently laboring under a poor understanding of Python scoping. Perhaps you can help. Background: I'm using the 'if name in "main"' construct to perform "self-tests" in my module(s). Each self test makes calls to the various public methods and prints their results for visual checking as I develop the modules. To keep things "purdy" and manageable, I've created a small method to simplify the testing of method calls: def pprint_vars(var_in): print("%s = '%s'" % (var_in, eval(var_in))) Calling pprint_vars with: pprint_vars('some_variable_name') prints: some_variable_name = 'foo' All fine and good. Problem statement: Not happy to just KISS, I had the brain-drizzle to move my handy-dandy 'pprint_vars' method into a separate file named 'debug_tools.py' and simply import 'debug_tools' whenever I wanted access to 'pprint_vars'. Here's where things fall apart. I would expect import debug_tools foo = bar debug_tools.pprint_vars('foo') to continue working its magic and print: foo = 'bar' Instead, it greets me with: NameError: name 'some_var' is not defined Irrational belief: I believed (apparently mistakenly) that import puts imported methods (more or less) "inline" with the code, and thus the variable scoping rules would remain similar to if the method were defined inline. Plea for help: Can someone please correct my (mis)understanding of scoping regards imports? Thanks, JS

    Read the article

  • Rails Named Scope and overlapping conditions

    - by Tumtu
    Hi everyone, have a question about rails SQL generation: class Organization < ActiveRecord::Base has_many :people named_scope :active, :conditions => { :active => 'Yes' } end class Person < ActiveRecord::Base belongs_to :organization end Rails SQL for all active people in the first organiztion Organization.first.people.active.all [4;36;1mOrganization Load (0.0ms)[0m [0;1mSELECT TOP 1 * FROM [organizations] [0m [4;35;1mPerson Load (0.0ms)[0m [0mSELECT * FROM [people] WHERE ((([people].[active] = 'Yes') AND ([people].organization_id = 1)) AND ([people].organization_id = 1)) [0m Why Rails generates "[people].organization_id = 1" condition twice ? Does someone know how to make it DRY ? e.g. SELECT * FROM [people] WHERE (([people].[active] = 'Yes') AND ([people].organization_id = 1))

    Read the article

  • PHP scope question

    - by Dan
    Hi, I'm trying to look through an array of records (staff members), in this loop, I call a function which returns another array of records (appointments for each staff member). foreach($staffmembers as $staffmember) { $staffmember['appointments'] = get_staffmember_appointments_for_day($staffmember); // print_r($staffmember['appointments'] works fine } This is working OK, however, later on in the script, I need to loop through the records again, this time making use of the appointment arrays, however they are unavailable. foreach ($staffmembers as $staffmember) { //do some other stuff //print_r($staffmember['appointments'] no longer does anything } Normally, I would perform the function from the first loop, within the second, however this loop is already nested within two others, which would cause the same sql query to be run 168 times. Can anyone suggest a workaround? Any advice would be greatly appreciated. Thanks

    Read the article

  • Property Scope (Iphone)

    - by Hank
    Hello All. I am having trouble accessing a declared property and I think I am missing something fundamental about the nature of properties and perhaps view controllers. Here's what I'm doing so far: declaring a property "myPhone" in a root view controller called RootViewController. grabbing a phone number from a modally presented people picker setting "myPhone" to the value from the people picker (from within shouldContinueAfterSelectingPerson of ABPeoplePickerNavigationController) trying to access "myPhone" from another modally presented view controller "myPhone" continues to NSLog to null despite trying every permutation of self.myPhone, super, RootViewController, etc. to try and access the value I set. What am I missing?

    Read the article

  • Javascript: Access the right scope "under" apply(...)

    - by Chau
    This is a very old problem, but I cannot seem to get my head around the other solutions presented here. I have an object function ObjA() { var a = 1; this.methodA = function() { alert(a); } } which is instantiated like var myObjA = new ObjA(); Later on, I assign my methodA as a handler function in an external Javascript Framework, which invokes it using the apply(...) method. When the external framework executes my methodA, this belongs to the framework function invoking my method. Since I cannot change how my method is called, how do I regain access to the private variable a? My research tells me, that closures might be what I'm looking for.

    Read the article

  • jQuery variables and scope

    - by Peuge
    I am writing a jQuery plugin and am running into a few problems with regard to variables. For example I have the following skeleton structure for my plugin, which is going to act on a textbox. In my init function I want to set a variable and bind a keypress event to my textbox. That keypress event needs to call another function, in which I need the variable. Is this possible? (function($){ var methods = { init : function(options){ return this.each(function(){ var $this = $(this); var someVar = 'somevar'; $this.keypress(function(event){ //I want to call my customFunction }); }); }, customFunction : function(){ //I am wanting to access 'someVar' here }; $.fn.mynamespace = function(method){ //handle which method to call here }; })(jQuery); Many thanks in advance.

    Read the article

  • C pointer array scope and function calls

    - by juvenis
    I have this situation: { float foo[10]; for (int i = 0; i < 10; i++) { foo[i] = 1.0f; } object.function1(foo); // stores the float pointer to a const void* member of object } object.function2(); // uses the stored void pointer Are the contents of the float pointer unknown in the second function call? It seems that I get weird results when I run my program. But if I declare the float foo[10] to be const and initialize it in the declaration, I get correct results. Why is this happening?

    Read the article

  • How do I scope variables properly in jQuery?

    - by safetycopy
    I'm working on a jQuery plugin, but am having some trouble getting my variables properly scoped. Here's an example from my code: (function($) { $.fn.ksana = function(userOptions) { var o = $.extend({}, $.fn.ksana.defaultOptions, userOptions); return this.each(function() { alert(rotate()); // o is not defined }); }; function rotate() { return Math.round(o.negRot + (Math.random() * (o.posRot - o.negRot))); }; $.fn.ksana.defaultOptions = { negRot: -20, posRot: 20 }; })(jQuery); I'm trying to get the private function rotate to be able to see the o variable, but it just keeps alerting 'o is not defined'. I'm not sure what I'm doing wrong.

    Read the article

  • Variable scope problem in JavaScript

    - by dfjhdfjhdf
    I declare a variable with the var word inside a function that handles Ajax requests, then later on in the function I have another function that should change the value of the variable but - my problem - it fails. How to settle the problem down? Here's similiar code I use: function sendRuest(someargums) { /* some code */ var the_variable; /* some code */ //here's that other function request.onreadystatechange = function() { if (request.readyState == 4) { switch (request.status) { case 200: //here the variable should be changed the_variable = request.responseXML; /* a lot of code */ //somewhere here the function closes } return the_variable; } var data = sendRequest(someargums); //and trying to read the data I get the undefined value

    Read the article

  • Global JavaScript Variable Scope: Why doesn't this work?

    - by CoryDorning
    So I'm playing around with JavaScript and came across what I think to be an oddity. Is anyone able to explain the following? (i've included the alerted values as comments) Why is the first alert(msg) inside foo() returning undefined and not outside? var msg = 'outside'; function foo() { alert(msg); // undefined var msg = 'inside'; alert(msg); // inside } foo(); alert(msg); // outside Considering these both work fine: var msg = 'outside'; function foo() { alert(msg); // outside } alert(msg); // outside and: var msg = 'outside'; function foo() { var msg = 'inside'; alert(msg); // inside } alert(msg); // outside

    Read the article

  • Basic Python: Exception raising and local variable scope / binding

    - by SuperJdynamite
    I have a basic "best practices" Python question. I see that there are already StackOverflow answers tangentially related to this question but they're mired in complicated examples or involve multiple factors. Given this code: #!/usr/bin/python def test_function(): try: a = str(5) raise b = str(6) except: print b test_function() what is the best way to avoid the inevitable "UnboundLocalError: local variable 'b' referenced before assignment" that I'm going to get in the exception handler? Does python have an elegant way to handle this? If not, what about an inelegant way? In a complicated function I'd prefer to avoid testing the existence of every local variable before I, for example, printed debug information about them.

    Read the article

  • Accessing variables with different scope in C++

    - by Portablejim
    With #include <iostream> using namespace std; int a = 1; int main() { int a = 2; if(true) { int a = 3; cout << a << " " << ::a // Can I access a = 2 here? << " " << ::a << endl; } cout << a << " " << ::a << endl; } having the output 3 1 1 2 1 Is there a way to access the 'a' equal to 2 inside the if statement where there is the 'a' equal to 3, with the output 3 2 1 2 1 Note: I know this should not be done (and the code should not get to the point where I need to ask). This question is more "can it be done".

    Read the article

  • Android Static Variable Scope and Lifetime

    - by Edison
    I have an application that has a Service uses a ArrayList to store in the background for a very long time, the variable is initialized when the service started. The service is in the background and there will be frequent access to the variable (that's why i don't want to use file management or settings since it will be very expensive for a file I/O for the sake of battery life). The variable will likely to be ~1MB-2MB over its life tie. Is it safe to say that it will never be nulled by GC or the system or is there any way to prevent it? Thanks.

    Read the article

  • Coffeescript getting proper scope from callback method

    - by pandabrand
    I've searched for this and can't seem to find an successful answer, I'm using a jQuerey ajax call and I can't get the response out to the callback. Here's my coffeescript code: initialize: (@blog, @posts) -> _url = @blog.url _simpleName = _url.substr 7, _url.length _avatarURL = exports.tumblrURL + _simpleName + 'avatar/128' $.ajax url: _avatarURL dataType: "jsonp" jsonp: "jsonp" (data, status) => handleData(data) handleData: (data) => console.log data @avatar = data Here's the compiled JS: Blog.prototype.initialize = function(blog, posts) { var _avatarURL, _simpleName, _url, _this = this; this.blog = blog; this.posts = posts; _url = this.blog.url; _simpleName = _url.substr(7, _url.length); _avatarURL = exports.tumblrURL + _simpleName + 'avatar/128'; return $.ajax({ url: _avatarURL, dataType: "jsonp", jsonp: "jsonp" }, function(data, status) { return handleData(data); }); }; Blog.prototype.handleData = function(data) { console.log(data); return this.avatar = data; }; I've tried a dozen variations and I can't figure out how to write this? Thanks.

    Read the article

  • How can I timeout Client-scoped variables in Coldfusion?

    - by Joshua Carmody
    I apologize if this is a "duh" question. It seems like the answer should be easily googleable, but I haven't found it yet. I am working on a large Coldfusion application that stores a large amount of session/user data in the Client scope (ie <cfset Client.UserName = "JoshuaC"> ). I did not write this application, and I don't have the luxury of significantly refactoring it. I've been given the task of setting the Client variables to time out after 72 hours. I'm not entirely sure how to do this. If I had written the application, I would have stored the variables in the Session scope, and then changed the sessiontimeout attribute of the CFAPPLICATION tag. As it is though, I'm not sure if that timeout affects the Client variables, or what their level of persistence is. The way the application works now, the Client variables never time out, and only clearing the user's cookies, or visiting a logout page which sets all the Client-scoped application variables to "", will clear the values. Of course, I could create some kind of timestamp variable like Client.LastAccessDateTime, and put something in the Application.cfm to clear the client variables if that datetime is more than 72 hours prior to Now(). But there's got to be a better way, right?

    Read the article

  • What is the JavaScript variable scope in a switch / case statment?

    - by Todd Moses
    While creating JavaScript with ASP.NET MVC I noticed several scope warnings and realized that I am missing something with understanding the variable scope inside the switch / case statement. Warning: 'i' is already defined referring to case b and case c My code looks similar to this: switch(element) { case 'a': for(var i=0; i < count; i++){ do something } break; case 'b': for(var i=0; i < count; i++){ do something } break; case 'c': for(var i=0; i < count; i++){ do something } break; } I thought scope ended with each break statement but it seems that scope does not end until the end of the switch/case. Is scope for the entire switch/case?

    Read the article

  • Defining scope for Record Count functoid:

    - by ArunManick
    Defining scope for Record Count functoid: Problem: One of the most common scenarios in BizTalk is calculating the record count of repeating structure. BizTalk has come up with an advanced functoid called Record Count functoid which will give the record count for the repeating structure however you cannot define the scope for a Record Count functoid. Because Record Count functoid accepts exactly one parameter which can be repeating record or field element.   If somebody don’t know what “scope” means I will explain with a simple example. Consider that we have a source schema having a structure Country -> State -> City. Country will have various states and each state will have different cities. Now you want to calculate no. of cities present in each state. Here scope is defined at the parent node “State”. Traditional Record Count functoid will give the total no. of cities present in the source message and not the State level city count.   Source Schema:   Destination Schema:   Soultion #1: As the title indicates we are not going to add one more parameter to the record count functoid. Instead of that, we are going to achieve the solution with the help of Scripting functoid with Inline XSLT script. XSLT is basically the transformation language used in the mapping.     “No.OfCities” indicates the destination field name to which we are going to send the value. In count(City), “count” refers to built in XPath function used in XSLT and “City” refers to source schema record name. Here you can find the list of built-in functions available in XSLT.   The mapping will look like as follows:   The 2 Record Count functoids used in this map will give the total number of states and total number of cities as that of input message.   Soultion #2:  If someone doesn’t like XSLT code and they wish to achieve the solution using functoids alone, then here is another solution.   Use logical Existence functoid to check whether “City” exist or not Connect the output of Logical Existence functoid to the Value Mapping functoid with second parameter as constant “1”. Hence if the first parameter is TRUE it will give the output as “1”. Connect the output of Value Mapping functoid to the Cumulative Sum functoid with scope as “1”   This will calculate the City count at the state level. The mapping will look like as follows:     Let us see the sample input and the map output.   Input: <?xml version="1.0" encoding="utf-8"?> <ns0:Country xmlns:ns0="http://RecordCount.Source">   <State>     <StateName>Tamilnadu</StateName>     <City>       <CityName>Pollachi</CityName>     </City>     <City>       <CityName>Coimbatore</CityName>     </City>     <City>       <CityName>Chennai</CityName>     </City>   </State>   <State>     <StateName>Kerala</StateName>     <City>       <CityName>Palakad</CityName>     </City>   </State>   <State>     <StateName>Karnataka</StateName>     <City>       <CityName>Bangalore</CityName>     </City>     <City>       <CityName>Mangalore</CityName>     </City>   </State> </ns0:Country>     Output: <ns0:Country xmlns:ns0="http://RecordCount.Destination">           <No.OfStates>3</No.OfStates>           <No.OfCities>6</No.OfCities>           <States>                    <No.OfCities>3</No.OfCities>           </States>           <States>                    <No.OfCities>1</No.OfCities>           </States>           <States>                    <No.OfCities>2</No.OfCities>           </States> </ns0:Country>   Conclusion: This is my first post and I hope you enjoyed it.   -Arun

    Read the article

  • Why do you have to explicitly specify scope with friendly_id?

    - by nfm
    I'm using the friendly_id gem. I also have my routes nested: # config/routes.rb map.resources :users do |user| user.resources :events end So I have URLs like /users/nfm/events/birthday-2009. In my models, I want the event title to be scoped to the username, so that both nfm and mrmagoo can have events birthday-2009 without them being slugged. # app/models/event.rb def Event < ActiveRecord::Base has_friendly_id :title, :use_slug => true, :scope => :user belongs_to :user ... end I'm also using has_friendly_id :username in my User model. However, in my controller, I'm only pulling out events pertinent to the user who is logged in (current_user): def EventsController < ApplicationController def show @event = current_user.events.find(params[:id]) end ... end This doesn't work; I get the error ActiveRecord::RecordNotFound; expected scope but got none. # This works @event = current_user.events.find(params[:id], :scope => 'nfm') # This doesn't work, even though User has_friendly_id, so current_user.to_param _should_ return "nfm" @event = current_user.events.find(params[:id], :scope => current_user) # But this does work! @event = current_user.events.find(params[:id], :scope => current_user.to_param) SO, why do I need to explicitly specify :scope if I'm restricting it to current_user.events anyway? And why does current_user.to_param need to be called explicitly? Can I override this?

    Read the article

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