scope

A function inside a for loop with jQuery and Javascript

允我心安 提交于 2019-12-08 01:01:37
问题 i have the following code : $(document).ready(function () { for (i = 1; i <= number_of_banners; i++) { var selector = "#link_" + i; $(selector).click(function () { alert(i); }); } }); but the alert() can't get the "i" variable from the for loop. How can I use the i variable of for loop inside the .click function ? 回答1: you can use this code : $(document).ready(function () { for (var i = 1; i <= number_of_banners; i++) { var selector = "#link_" + i; $(selector).on('click', {id: i}, function (e

Struts 2 bean configuration default scope

筅森魡賤 提交于 2019-12-07 23:58:30
问题 I'm trying to use basic DI with Struts2 using the configuration file as described here. However, I was not able to find what the default scope is for injecting a bean. I know that the default scope is Singleton for Spring but I didn't want to assume the same with Struts2. Any ideas? 回答1: The default scope is singleton , but there's a scope with name default which is different. May be this question let you better understand scopes in Struts2. The framework support scopes like singleton ,

How to make directive re-render view in Angular?

那年仲夏 提交于 2019-12-07 23:46:20
问题 I would like to truncate text dynamically, on each data change and each window's resize event. Lets's say I have a HTML: <p ng-truncate='lines: 2'> Lorem ipsum dolor...</p> My directive does the truncation, but still it lacks of re-truncation on window's resize. angular.module('moduleName', []) .directive 'ngTruncate', () -> link: (scope, element, attributes) -> // Direcive code here $(window).on 'resize', -> scope.$apply() scope.$digest() Unfortunatelly, $apply , nor $digest() do not work.

Scope issue while creating objects inside if statement if C++

╄→гoц情女王★ 提交于 2019-12-07 23:11:59
问题 This is supposed to be very basic. Layout: class handler { public: handler(Connection *conn) { connection = conn; } virtual void handle() = 0; }; class http_status : public handler { public: http_status(Connection *conn) : handler(conn) { } void handle(); }; class http_photoserver : public handler { public: http_photoserver(Connection *conn) : handler(conn) { } void handle(); }; Code: void pick_and_handle() { if (connection->http_header.uri_str != "/") { http_photoserver handler(connection);

Spring.NET and MVC3 on IIS7 - session scope behaviour

ⅰ亾dé卋堺 提交于 2019-12-07 21:26:22
问题 probably it's a stupid question and I simply did not understand how Spring and IIS work, but lets give it a try. I'm quite new to ASP.NET and as far as I understand, the session handling is similar to Apache/PHP: A session is shared between tabs of a browser, but not between different browsers. I.e. if I open my page in Firefox and put something in the cart, the cart will still contain my items in another tab, but opening the very same page in Internet Explorer should show me an empty cart.

Limiting Scope of #include Directives

吃可爱长大的小学妹 提交于 2019-12-07 20:50:33
问题 Let's say I have a header file with a class that uses std::string . #include <string> class Foo { std::string Bar; public: // ... } The user of this header file might not want std::string to be included in his/her project. So, how do I limit the inclusion to just the header file? 回答1: The user of your class must include <string> , otherwise their compiler will not know how big a Foo object is (and if Foo 's constructors/destructors are defined inline, then the compiler also won't know what

How does garbage collection work in PHP? Namely, how do local function variables get cleaned up?

谁都会走 提交于 2019-12-07 19:55:02
问题 If I assign a value to variable that is not declared global inside a function will that variable be unset automatically when function terminates or will it only be unset when the PHP script finishes executing? I'm trying to determine if it's smarter to unset temporary, function scope variables within the function manually or to not worry about because they will be automatically unset by the PHP engine. 回答1: The variable will be unset when the function exits, unless it has external references

Can you assign to a variable defined in a parent function? [duplicate]

佐手、 提交于 2019-12-07 19:30:16
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Python nested functions variable scoping After much trial and error I have eventually discovered that this doesn't work: def a(): def b(): print x x=2 x = 1 b() print x You get an exception (x not defined before being referenced). So it looks like b can read from x, but if it tries to assign to it, Python changes its interpretation of 'x' to be a local variable, which is now not defined. Question for my own sick

Do variables defined inside list comprehensions leak into the enclosing scope? [duplicate]

穿精又带淫゛_ 提交于 2019-12-07 18:57:29
问题 This question already has answers here : List comprehension rebinds names even after scope of comprehension. Is this right? (5 answers) Closed last year . I can't find anywhere that defines this behaviour: if [x for x in [0, 1, -1] if x > 0]: val = x How safe is this code? Will val always be assigned to the last element in the list if any element in the list is greater than 0? 回答1: In Python 2.x, variables defined inside list comprehensions leak into their enclosing scope, so yes, val will

Scope of jQuery each() function?

我怕爱的太早我们不能终老 提交于 2019-12-07 18:06:26
I'm working with the jQuery ColorPicker widget - specifically exercising the ColorPickerSetColor function (just 'setColor' internally). Code excerpt: setColor: function(col) { if (typeof col == 'string') { col = HexToHSB(col); } else if (col.r != undefined && col.g != undefined && col.b != undefined) { col = RGBToHSB(col); } else if (col.h != undefined && col.s != undefined && col.b != undefined) { col = fixHSB(col); } else { return this; } return this.each(function(){ if ($(this).data('colorpickerId')) { var cal = $('#' + $(this).data('colorpickerId')); cal.data('colorpicker').color = col;