jQuery Passing $(this) to a Function

you can check this link. http://jsfiddle.net/zEXrq/38/ $(“#f”).click(function() { myFunc($(this)); }) function myFunc(thisObj) { thisObj.parent().parent().children().each(function() { alert(“childs”) }); } <div id=”wordlist”> <div id=”a”></div> <div id=”b”> <div id=”e”></div> <div id=”f”>child</div> </div> </div> <script src=”https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js”></script>

requestAnimationFrame with this keyword

I’m trying to pass display.draw which is the function in which webkitRequestAnimationFram resides. webkitRequestAnimationFrame will presumably call the function you pass in, something like this: function webkitRequestAnimationFrame(callback) { // stuff… callback(); // other stuff… } At this point, you have dissociated (detached) the draw function from its invocation context. You need to bind the function … Read more

Why must I use the “this” keyword for forward references?

The full description is in section 8.3.3 of the Java Language Specification: “Forward References During Field Initialization“ A forward reference (referring to a variable that is not declared yet at that point) is only an error if the following are all true: The declaration of an instance variable in a class or interface C appears … Read more

jQuery $(this) keyword

When you perform an DOM query through jQuery like $(‘class-name’) it actively searched the DOM for that element and returns that element with all the jQuery prototype methods attached. When you’re within the jQuery chain or event you don’t have to rerun the DOM query you can use the context $(this). Like so: $(‘.class-name’).on(‘click’, function(evt) … Read more

Changing the ‘this’ variable of value types

Good question! Value types are, by definition, copied by value. If this was not actually an alias to a storage location then the constructor would be initializing a copy rather than initializing the variable you intend to initialize. Which would make the constructor rather less useful! And similarly for methods; yes, mutable structs are evil … Read more

How to function call using ‘this’ inside forEach loop

You can store this in variable: var self = this; this.addNewObjects = function(arr){ arr.forEach(function(obj) { self.addObject(new Obj(obj.prop1, obj.prop2)); }); } or use bind: this.addNewObjects = function(arr) { arr.forEach(function(obj) { this.addObject(new Obj(obj.prop1, obj.prop2)); }.bind(this)); } And side note, without those this will be window object not obj. This is always object that was created using new … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)