this

get parentNode of clicked element in plain JS

两盒软妹~` 提交于 2019-12-06 01:34:04
问题 I need to get the parentNode of a clicked element in plain JS (no jQuery or other frameworks) I am currently using document.getElementById("item_click") but I want to change id="item_click" to class="item_click" so I can use multiple boxes. I just don't know how to integrate this in the script Here's a Fiddle <<< play with it HTML <div class="item"> <div class="item-tester" > <div class="item-icon"></div> <div class="item-title">Item Title</div> </div> <div id="item_click" onmousedown="new

Why am I failing to capture the “this” pointer by a lambda?

自古美人都是妖i 提交于 2019-12-05 23:23:04
问题 Consider the following code: class A { public: void foo() { auto functor = [this]() { A * a = this; auto functor = [a]() // The compiler won't accept "this" instead of "a" { a->bar(); }; }; } void bar() {} }; In VC2010, using this instead of a lead to compilation errors. Among others: 1>main.cpp(20): error C3480: '`anonymous-namespace'::<lambda0>::__this': a lambda capture variable must be from an enclosing function scope 1>main.cpp(22): error C3493: 'this' cannot be implicitly captured

Intern: loop on Promise.<Array.<leadfoot/Element>>

回眸只為那壹抹淺笑 提交于 2019-12-05 22:51:33
Let's say I have the following DOM structure, for simplicity: <div class='myparent'> <div class='child'> <div class="label">A</div> <div class="ico"/> </div> <div class='child'> <div class="label">B</div> <div class="ico"/> </div> <div class='child'> <div class="label">C</div> <div class="ico"/> </div> </div> I would like to loop within all child Element returned by the function findAllByCssSelector('.child'). In particular, I would click on the ico div subelement ONLY if the label of the div is B. I would remember, that findAllByCssSelector() returns Promise.<Array.<leadfoot/Element>> .

Google Closure Compiler: How to preserve code that caches “this”?

元气小坏坏 提交于 2019-12-05 21:57:19
Introduction I use Google Closure Compiler frequently for compressing my JavaScript files. Now, it seems to compress my code fairly well. Now, I try to make a habit of storing the this object in a local variable, because this cannot be obfuscated, but a local variable certainly can be obfuscated. However, Google Closure Compiler does not recognize this, and instead removes all instances of the local variable, replacing it with this . Regarding optimization... I am well aware that one should avoid pre-optimization when writing code. However, I feel that caching this is acceptable because doing

Issue with child scoping of this in Typescript

被刻印的时光 ゝ 提交于 2019-12-05 19:25:16
This is ALMOST the same as every other this scoping question I have read so far other than one slight difference which makes it relevant (imo) to ask this question. Now originally my problem was scoping of this with Knockout and Typescript, so given the following: class ViewModel { public SomeObservableArray = new ko.observableArray(); public AddToTheObservableArray(someJsonData: any) { this.SomeObservableArray.push(new SomePojo(someJsonData)); } } So the this bit in the above code would blow up because Typescript makes you think that this is the class instance, but in reality it is some other

jQuery each - combining (this) with class specification

☆樱花仙子☆ 提交于 2019-12-05 16:58:31
I'm trying to cycle through some table rows. The simplified rows are as follows: <table> <tr id="ucf48"> <td class="ucf_text"> <input name="ucf_t48" value="Ann becomes very involved in the text she is reading." type="text"> </td> </tr> <tr id="ucf351"> <td class="ucf_text"> <input name="ucf_t351" value="Ann is a fast and confident reader." type="text"> </td> </tr> </table> I'm using this code to cycle: $('#ucf tr').each(function(i,obj){ var cn=$(this).attr('id').substr(3); var t=$(this +'.ucf_text input').val(); console.log("Row "+i); console.log("Cnum: "+cn); console.log(t); }); The console

What is 'this' before an object is instantiated in js?

僤鯓⒐⒋嵵緔 提交于 2019-12-05 16:14:19
I don't understand the following: var x = function() { this.foo="foo"; return function() { this.bar = "bar"; return foo+bar; }; }(); // returns inner alert(x()); // 'foobar', so both 'this' variables are set alert(x.bar); // undefined - but wasn't it used correctly? alert(new x().bar); // ok, works My assumption was that a default 'this' scope/variable-map is generated and used the first time, and then when 'new' is called, a new object (function?) with a new 'this' is sent through and returned. Or, perhaps x isn't a proper object? But then, how does 'this' end up being set and used to make

Forcing the context

佐手、 提交于 2019-12-05 16:13:36
I have this class where I have a private property and a public method for access: Person = function () { this.Name = "asd"; var _public = new Object(); _public.Name = function (value) { if (value == undefined) { //Get return this.Name } else { this.Name = value; //Set } }; return _public; }; I want to force the context in _public.Name for access a this.Name . I know the technique of closure, but I want to see if I can force a context. I found a technique to do it, extend object Function: Function.prototype.setScope = function (scope) { var f = this; return function () { f().apply(scope); } }

Angular/Typescript Eval and this

让人想犯罪 __ 提交于 2019-12-05 12:59:48
So I am having a problem understanding how eval works with this in typescript/angular. Could someone please help me get the eval to work here? This is just a demo program so just ignore the fact that the logic doesn't make sense. I would just like to have eval update a dynamic array with a dynamic value. https://stackblitz.com/edit/angular-pfyt7q?file=src%2Fapp%2Fapp.component.ts export class AppComponent { arrTest1 = []; arrTest2 = []; arrTest3 = []; constructor() { this.TestClass.Run("this.arrTest1 = [1];"); this.TestClass.Run("this.arrTest2 = [2];"); this.TestClass.Run("this.arrTest3 = [3];

Javascript static/singelton - this vs _this vs object name

家住魔仙堡 提交于 2019-12-05 12:08:26
This is a question about performance and best practice. Assuming I have a js object that encapsulates a large number of helper methods. The object is being treated as a static class, meaning it is never instantiated and all its methods are basically helper methods. When using events and jQuery, the object's this scope keeps changing, and since it has a fairly large number of methods I am wondering what is best practice - saving this into _this at the beginning of each method or simply use the object name MyObject . Over the years I've been doing both, when it comes to singelton/static objects,