lang
stringclasses
4 values
desc
stringlengths
2
8.98k
code
stringlengths
7
36.2k
title
stringlengths
12
162
JS
Is it possible to override a function in a Javascript class , and call it 's base implementation ? I 've achieved this by using prototypes , but I 'm trying to preserve privacy for some of the data.This is what I have so far , and it does n't work . I can see why it does n't work , but I ca n't see a way to resolve it ...
var NoProto = NoProto || { } ; NoProto.Shape = ( function ( ) { var thing = function ( name ) { var privateData = 'this is a ' + name ; var self = this ; this.base = function ( ) { return self ; } ; this.doStuff = function ( ) { return privateData ; } ; } ; return thing ; } ) ( ) ; NoProto.Square = ( function ( ) { var...
How to override a function in a Javascript class , and call the base function
JS
Under Properties- > '' onreadystatechange '' - > Type : Function ? , What does the ? mean ?
Attribute Type Description -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- onreadystatechange Function ? [ ... ] ^
Mozilla developer network - What does the question mark refer to ?
JS
If I implemented a method x on a String like : And then the new version of javascript actually implements the x method , but on the another way , either returning something different than my implementation or function with more/less arguments than my implementation . Will this break my implementation and override it ?
String.prototype.x = function ( a ) { ... }
Implementing prototype method
JS
How would I add types for compose ? The problem basically boils down to writing the types for this : and using it : In this example , the type of compose is inferred to : Which is just a bunch of any ... Is there a good way to add types to compose ?
const compose = ( ... funcs ) = > x = > funcs.reduce ( ( acc , func ) = > func ( acc ) , x ) ; compose ( x = > x + 1 , x = > x * 2 ) ( 3 ) ; const compose : ( ... funcs : any [ ] ) = > ( x : any ) = > any
Type system for function composition
JS
Looking for a more `` functional '' way of achieving this ... I have an object of products that looks like this ( note duplicate skuid 's ) I want to create a new array that has a single object for each distinct skuid but that SUMS all the quantity values and retains the newest lastOrderedDate.The final result would lo...
`` products '' : [ { `` skuid '' : `` B1418 '' , `` name '' : `` Test Product 1 '' , `` price '' : 7 , `` lastOrderedDate '' : 20181114 , `` quantity '' : 2 } , { `` skuid '' : `` B3446 '' , `` name '' : `` Test Product 2 '' , `` price '' : 6 , `` lastOrderedDate '' : 20190114 , `` quantity '' : 2 } , { `` skuid '' : `...
Javascript : Collapse array of objects on property value , summing quantity property , retaining most recent
JS
On the following command , I get the following errorConsole outputI 'm confused as I have specified the coffeescript package under Package.onUse.rocketchat-spotify/package.jsAdding the coffeescript package as follows resolves the issueConsole outputVersion info
$ meteor test-packages -- driver-package practicalmeteor : mocha rocketchat : spotify = > Errors prevented startup : While building package local-test : rocketchat : spotify : error : No plugin known to handle file 'spotify.test.coffee ' . If you want this file to be a static asset , use addAssets instead of addFiles ;...
Why do I have to duplicate packages that I specified in Package.onUse in Package.onTest in Meteor ?
JS
In JavaScript , you will often see functions which say document.getElementById ( `` element '' ) .someFunction ( ) ; or $ ( `` element '' ) .someFunction ( ) ; instead of someFunction ( $ ( `` element '' ) ) ; . Where someFunction ( element ) looks a little like the following code.My question is how do you make a funct...
someFunction ( element ) { //element.doSomething ( ) ; }
How to make a function to go after an element
JS
considering the following javascript code ( partially taken from Apollo Server documentation ) , it creates an instance of ApolloServer and start it.Now consider to replicate the same behaviour using KotlinJS.Firstly , Kotlin does n't have the `` new '' keyword and calling ApolloServer ( ) as expected , wo n't work but...
const { ApolloServer } = require ( 'apollo-server ' ) const server = new ApolloServer ( { ... } ) ; server.listen ( ) .then ( ( { url } ) = > { console.log ( ` Server ready at $ { url } ` ) ; } ) ; // We can banally represent part of the code above like : external fun require ( module : String ) : dynamicval ApolloServ...
Instantiate Javascript classes that expect `` new '' keyword on KotlinJS
JS
So I 'm learning prototype using javascript , and tried some code : Unfortunately , I get an undefined message , instead of the true value . Is there a reason to this result ? I have made several tests . I 've concluded that reassigning the prototype object causes any previously created instances of the Employee class ...
function Employee ( name ) { this.name= name ; } var m = new Employee ( `` Bob '' ) ; var working= { isWorking : true } ; Employee.prototype = working ; alert ( m.isWorking ) ;
undefined result using prototype [ javascript ]
JS
I just came across this FIDDLE online . The JS looks like below : HTML : :Its basically just a piece of JS interchanging a select values . But what I do n't understand is the usage of the ! operator ( not operator ) .Now I understand that the not operator inverses the result , but in the above code what is it really do...
$ ( function ( ) { $ ( ' # add ' ) .click ( function ( ) { return ! $ ( ' # select1 option : selected ' ) .appendTo ( ' # select2 ' ) ; } ) ; $ ( ' # remove ' ) .click ( function ( ) { return ! $ ( ' # select2 option : selected ' ) .appendTo ( ' # select1 ' ) ; } ) ; } ) ; < SELECT id= '' select1 '' name= '' select1 ''...
Understanding usage of not operator in : selected
JS
I have a div with the contenteditable attribute . The user needs to be able to type and insert several select menus where the cursor is . I 've managed to get the cursor position and to insert the first select menu , but it only works on the first text node.That 's how I get the cursor position : Then I update it every...
function getCaretCharacterOffsetWithin ( element ) { var caretOffset = 0 ; var doc = element.ownerDocument || element.document ; var win = doc.defaultView || doc.parentWindow ; var sel ; if ( typeof win.getSelection ! = `` undefined '' ) { sel = win.getSelection ( ) ; if ( sel.rangeCount > 0 ) { var range = win.getSele...
Insert several elements inside an editable div at cursor position
JS
It 's been frequently used that we initiate a variable synchronously.But when the initiator becomes async , there would be a problem.I tried anonymous async initiator , it 's not perfect.Then I tried to export the function in the anonymous async initiator , failed again.So , is there a better solution ?
const x = call_a_sync_function ( ) ; const x = await call_an_async_function ( ) ; // SyntaxError : Unexpected reserved word let x ; ( async ( ) = > x = await call_an_async_function ( ) ) ( ) ; export function func ( ) { call ( x ) ; // x would be undefined if func ( ) is called too early . } ( async ( ) = > { const x =...
Async initiator in Javascript
JS
What is more efficient for a 'live search function ' ? On keyup with a little delay is a request made , the records come back in json and I append those on this way : But I can generate the full table in php and then append it like this : NOTE : In the php code I loop through each result and add some values to it , tha...
$ .ajax ( { type : `` POST '' , url : `` /spares/search/getresults '' , dataType : `` json '' , data : `` val= '' + searchval , success : function ( response ) { if ( response.error == false ) { $ .each ( response.result , function ( index , value ) { $ ( `` .choosCred '' ) .append ( `` < tr class='productChoose ' > < ...
What is more efficient ? Generate each tr in javascript or in php ?
JS
if i have this function : when I run it as : i will get a window.good , instead of passing a parameter as string.. i need pass a parameter as function , like that : then i run : So how can I pass a function as a parameter to another function ?
function test ( x ) { alert ( x ) ; } test ( 'hello world ' ) ; function test ( x ) { x ; } test ( alert ( 'hello world ' ) ) ;
how can i pass variable in parameter as a function ?
JS
This is what I have so far : https : //jsfiddle.net/86xyxvyn/I am trying to add multiple divs to this sketch so that each one bounces around the black box independently . Ideally , each word would also have a unique starting position ( not just in the upper left hand corner ) .
var vx = 3 ; var vy = 2 ; function hitLR ( el , bounding ) { if ( el.offsetLeft < = 0 & & vx < 0 ) { console.log ( 'LEFT ' ) ; vx = -1 * vx ; } if ( ( el.offsetLeft + el.offsetWidth ) > = bounding.offsetWidth ) { console.log ( 'RIGHT ' ) ; vx = -1 * vx ; } if ( el.offsetTop < = 0 & & vy < 0 ) { console.log ( 'TOP ' ) ;...
How to add multiple bouncing divs with different starting points using Jquery
JS
I am tracking URLs with `` posName '' parameters like : example.com ? posName=Content+ & +Community+Manager+ ( H/F ) But my code returns `` Content '' only : How can I get the full parameter ? EDIT : I have another URL like : exemple.com ? posName=Club+ & +Animator+ ( H/F ) And the code returns the full parameter ... S...
function ( ) { var uri = document.location.href ; var uri_dec = decodeURIComponent ( uri ) ; var url = new URL ( uri_dec ) ; var posName= url.searchParams.get ( `` posName '' ) ; return posName ; }
Why is the URL parameter I want to retrieve not fully displayed ?
JS
Why there is a difference in map ( ) output in the below code ?
var y = [ 1,2,2,1 ] ; var t = y.map ( ind = > [ ... Array ( ind ) ] .map ( ( _ , i ) = > ind+ '' '' +i ) ) ; // This makes [ [ '10 ' ] , [ '20 ' , '21 ' ] , [ '20 ' , '21 ' ] , [ '10 ' ] ] var t1 = y.map ( ind = > Array ( ind ) .map ( ( _ , i ) = > ind+ '' '' +i ) ) ; // [ [ < 1 empty item > ] , [ < 2 empty items > ] ,...
Difference between Array ( n ) and [ ... Array ( n ) ]
JS
I have a situation , where I want to position certain elements based on an event . For example : when I mouse over on # leftBox .green , I want all elements in # rightBox with .green on top , like : and like the same for .blue and .red
< div id= '' leftBox '' > < div class= '' green '' > GREEN < /div > < div class= '' blue '' > BLUE < /div > < div class= '' red '' > RED < /div > < /div > < div id= '' rightBox '' > < div class= '' green '' > GREEN < /div > < div class= '' blue '' > BLUE < /div > < div class= '' red '' > RED < /div > < div class= '' gr...
how to order elements on an event using jquery
JS
I have encountered some example JSX code in a book which took me by surprise - it contains an anchor tag in the single ( non-closed ) form . I have simplified the code : The code works , but I have n't been able to find any documentation that describes this way of describing the anchor tag in JSX . I expected to have t...
function CustomAnchor ( props ) { return < a { ... props } / > ; } ; ReactDOM.render ( < CustomAnchor href= '' http : //reactjs.com '' > A link < /CustomAnchor > , document.getElementById ( 'container ' ) ) ;
Undocumented method of passing element children : as attributes instead of explicit children
JS
I 'm trying to change the design of my hamburger navigation as the user scrolls . I feel I have come semi close https : //jsfiddle.net/g95kk7yh/6/Here is what I 'm trying to achieveThe main problem I 'm having is assigning the correct width and height of the red box without repositioning the navigation menu as a whole....
$ ( document ) .ready ( function ( ) { var scroll_pos = 0 ; $ ( document ) .scroll ( function ( ) { scroll_pos = $ ( this ) .scrollTop ( ) ; if ( scroll_pos > 10 ) { $ ( `` .navigation '' ) .css ( 'background ' , 'rgba ( 255 , 0 , 0 , 0.5 ) ' ) ; $ ( `` .navigation span '' ) .css ( 'background ' , ' # bdccd4 ' ) ; } el...
Trouble assigning background color on scroll
JS
I 'm trying to learn javascript Regex and I 've hit a problem.I 'm trying to validate with the following rules.Allow only : I have come up with the regex below to handle this : The following matches but should n't do because it contains a @ symbol : I 'm using the below to test : ( Returns true ) Thanks .
Numbers 0-9 ( ) +- ( space ) / [ 0-9\ ) \ ( \+\- ] +/i +0 @ 122 0012 / [ 0-9\ ) \ ( \+\- ] +/i.test ( `` +0 @ 122 0012 '' )
Basic Javascript Regex
JS
I 'm relatively new to JavaScript and am trying to get my head around the ES6 syntax specifically with if statements . I can create simple ES6 functions like : However , if I want to add an if statement , I can not get the ES6 syntax to work - for example : I know I can use the Math method to achieve the result via : B...
function test ( a , c ) { return a+c ; } [ 3,8 , -4,3 ] .reduce ( test ) ; function maxValue ( a , c ) { if ( c > = a ) { a == c } } [ 3,8 , -4,3 ] .reduce ( maxValue ) ; var array = [ 267 , 306 , 108 ] ; var largest = Math.max.apply ( Math , array ) ; // returns 306
Other ways of getting the highest array value
JS
I 've currently got 4 different javascripts for ad tracking . They look something like this : I want to combine all 4 and simply have the tracker key swap out based off the sub domain name they 're on.Thus far I 've been able to work out that I would use the window.location.hostname to find what the domain is . And I w...
< script type='text/javascript ' > var TrackerKey = 'keyabc123 ' ; var url = 'http : //website.com/jscode.js ' ; var script = document.createElement ( 'script ' ) ; script.setAttribute ( 'src ' , url ) ; script.setAttribute ( 'type ' , 'text/javascript ' ) ; document.body.appendChild ( script ) ; < /script > < script t...
Need Javascript to change an ad tracker key based off sub domain name
JS
I have the code : Why func1 return undefined while func2 return good value ( that i need ) ? Sorry for my english .
function func1 ( ) { return array.map ( function ( el ) { return el.method ( ) ; } ) ; } function func2 ( ) { var confused = array.map ( function ( el ) { return el.method ( ) ; } ) ; return confused ; }
confused about return array # map javascript
JS
I am trying to convert image to base64 . I have written the following code : But when i alert the readerEvt.target.result it says 131494 characters but when i load it to a variable only 10001 characters is loaded . This makes the image incomplete when decoded back from base64 . Any help will appreciated .
if ( file ) { var reader = new FileReader ( ) ; reader.onload = function ( readerEvt ) { alert ( readerEvt.target.result ) ; var image = readerEvt.target.result ; var base64image = image.split ( ' , ' ) [ 1 ] ; var key = 'image'+i ; images [ key ] = image ; // $ ( ' # image_preview ' ) .attr ( 'src ' , readerEvt.target...
Variable is incompletely loaded in javascript
JS
This ( below ) ended up giving me a `` maximum call stack size exceeded '' error . It seems like it 's due to the way `` this '' is being interpreted within the `` this.actions '' object . Within that object , does `` this '' refer to that object , or the instance of the Unit class ? If the former , would putting a .bi...
function Unit ( ) { this.move = function ( direction ) { switch ( direction ) { case 'up ' : { console.log ( 'foo ' ) ; break ; } case 'down ' : { console.log ( 'foooo ' ) ; break ; } } console.log ( 'bar ' ) ; } this.shoot = function ( ) { console.log ( 'zap ' ) } this.actions = { 'moveUp ' : function ( ) { this.move ...
Scope of `` this '' within object
JS
1st test:2nd test : In the first test , a is equal to 1 , although I set it to 10 in the method . In the second test , I set it to 10 and it is set to 10 when I output it.. How does this work ?
var a = 1 ; function b ( ) { a = 10 ; return ; function a ( ) { } } b ( ) ; alert ( a ) ; // 1 var a = 1 ; function b ( ) { a = 10 ; return ; } b ( ) ; alert ( a ) ; // 10
How to understand global and local variable in javascript
JS
I have the following code/snippet ; When signUp uses Arrow Syntax , the function does n't execute . When I use regular syntax ; It executes fine . Any idea as to what my problem is , here ?
class App extends React.Component { loginComponent = < button onClick= { this.signUp } > Sign Up < /button > ; signUp = ( ) = > { alert ( `` test '' ) ; } render ( ) { return ( < div > { this.loginComponent } < /div > ) } } ReactDOM.render ( < App / > , document.getElementById ( `` root '' ) ) ; # root { width : 50 % ;...
Arrow Function does n't trigger
JS
I have written a script that allows users to draw simple lines on top of an html 5 canvas element . The ultimate goal is to have this drawing being tiled and repeated across the rest of the browser . I have gotten a cloned canvas onto the page but am struggling on how to draw the same lines simultaneously on top of mul...
var size = 40 ; var md = false ; var canvas = document.getElementById ( 'canvas ' ) ; canvas.addEventListener ( 'mousedown ' , down ) ; canvas.addEventListener ( 'mouseup ' , toggledraw ) ; canvas.width = 600 ; canvas.height = 600 ; canvas.addEventListener ( 'mousemove ' , move ) ; function move ( evt ) { var mousePos ...
How do I update a cloned HTML canvas element with the context and data of the original canvas ?
JS
Earlier , I was creating a form and mindlessly named one of my inputs `` name '' , similar to the following pseudo code : I then remembered that in the past , I 've had issues with inputs with the name `` action . '' If I remember correctly , the issues arose during enhancement with JavaScript ( there was confusion bet...
< input id= '' name '' type= '' text '' name= '' name '' / >
Input names that should not be used ?
JS
I 've been looking for some solutions to solve this problem , but nothing helpsHere is my JavaScript code ( In JS Fiddle : https : //jsfiddle.net/1zj9dmq7/ ) I want when I click div a/b element , the `` alert '' function will not run , just running when clicked outside of that 2 elements , and without jQueryMaybe someo...
var specifiedElement = document.getElementById ( ' a ' ) ; document.addEventListener ( 'click ' , function ( event ) { var isClickInside = specifiedElement.contains ( event.target ) ; if ( ! isClickInside ) { alert ( 'You clicked outside A and B ' ) } } ) ; div { background : # aaa ; height:2em ; padding : 1em ; margin...
Detect click outside some elements
JS
Let 's run this javascript code : Why does this code outputs Nan in the console instead of null ? How can I change my code to actually get a null object ? I try to wrap my code in a function like this : But this behaves the same.Here is a jsFiddle that illustrate my issue : http : //jsfiddle.net/stevebeauge/BRP94/
var value = parseInt ( `` '' ) ; console.log ( value ! = Number.NaN ? value : null ) ; function parseIntOrDefault ( value , def ) { var candidate = parseInt ( value ) ; if ( candidate ! = Number.NaN ) return candidate ; else return def ; } console.log ( parseIntOrDefault ( `` , null ) ) ;
Why is n't this returning null ?
JS
I have this CSS to define drop areas , where a user can either drop a section before or after existing sections.Using JavaScript + JQuery here is the drop listener , that detects the element currently under the mouse : However container would be the same element for both the : before and : after case.How will I be able...
.section : before , .section : after { content : `` [ insert here ] '' ; height : 64px ; line-height : 56px ; width : 100 % ; display : block ; border : 3px dashed # aaa ; } elem.on ( 'drop ' , function ( e ) { e.preventDefault ( ) ; var container = $ ( elem [ 0 ] .elementFromPoint ( e.clientX , e.clientY ) ) ; } ) ;
How to detect wether the mouse is over the : before or over the : after part of an element
JS
I want to toggle element that id 's pg when click link.header : Elements :
< title > Example < /title > < script type= '' text/javascript '' src= '' jquery-1.3.2.js '' > < /script > < script type= '' text/javascript '' > $ ( function ( ) { $ ( `` # link '' ) .click ( function ( ) { $ ( `` # pg '' ) .toggle ( ) ; } ) ; < /script > < p id= '' pg '' > deneme deneme 123 deneme < /p > < a href= ''...
why my jquery codes does n't run ?
JS
What is the cleanest way to reduce those array ? For each id there is a v corresponding . What I want is sum up v for each id . In this example the result should be
data = { id : [ 1 , 1 , 1 , 3 , 3 , 4 , 5 , 5 , 5 , ... ] v : [ 10,10,10 , 5 , 10 ... ] } data = { id : [ 1 , 3 , 4 , 5 , ... ] v : [ 30 , 15 , ... ] }
javascript several corresponding array reducing/sumup
JS
based on : https : //developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/EventLoopstack frame is empty before next event is processed . So why in folowing snippet alert displays 1 instead of 0 because alert function should run before callbackhttp : //jsfiddle.net/nxjhokL0/Thanks !
var a=0 ; var b= { } ; $ ( b ) .on ( `` event '' , function ( ) { a++ ; } ) ; $ ( b ) .trigger ( `` event '' ) ; alert ( a ) ;
event loop model in javascript
JS
I 'm looking for the fastest way to lowercase all letters that are n't a part of AND in a phrase . I want to leave AND in its original case , whether it was and or AND should not change.For example , barack AND obama should test equal to Barack AND Obama but not barack and obama . ( notice the case difference in and ) ...
var str = 'Barack AND Obama ' ; // should be barack AND obama afterstr = str.split ( /\s+/g ) .map ( function ( s ) { return s.toLowerCase ( ) ! = 'and ' ? s.toLowerCase ( ) : s ; } ) .join ( ' ' ) ;
Lowercasing all words except AND
JS
Today I stumbled on this javascript snippet.I would like to know why this does n't throw a syntax error and more why y is 7 at the end ? What is the use of this strange snippet if there are any at all ? JSFiddle here
var x = 5 , y = 6 ; x++yalert ( x + `` `` + y ) ;
Why does this script increment y and not give a , for me expected , syntax error ?
JS
Iam trying to create a dropdown box for blog category using php and while editing the category form it should not be display the existing category name which i need to update in category form.Example i have a product electronics under that category i have laptop and mobile , if i update mobile in dropdown box mobile op...
< select name= '' category '' class= '' field '' style= '' width:160px '' > < option value= '' 0 '' > Select < /option > { var name='cat_ops ' } < /select > if ( $ _GET [ 'action ' ] == 'edit ' & & $ _GET [ 'id ' ] ) { $ sel_cat = $ cate_id ; } else { $ sel_cat = `` '' ; } construct_cat_ops ( $ sel_cat ) ; $ tmpl- > se...
While Updating the category in existing category , should not be displayed in dropdown box
JS
I am working on a project where I have to add a database value to in input value.In above code 680 will come from the database . Here I want to add an input number to that 680 . I am very new to jQuery.My JavaScript code isIn this it outputs `` NaN '' .
< div > < div class= '' price '' > 680 < /div > < div class= '' price '' > < input type= '' number '' name= '' name '' > < /div > < /div > $ ( document ) .ready ( function ( ) { var total = 0 ; $ ( `` input '' ) .keyup ( function ( ) { var priceList = $ ( '.price ' ) ; $ .each ( priceList , function ( i , price ) { tot...
Add an input value to a database value
JS
I have tried to execute the below code in Firefox V30.0 Scratchpad : The expected behavior is that my program should throw Reference Error , because I am accessing a let variable before it 's declaration . But , I am not getting the expected behavior , the program got executed and the result is as belowCan you explain ...
function do_something ( ) { console.log ( foo ) ; // ReferenceError let foo = 2 ; } do_something ( ) ; undefined
ReferenceError is not throwing when accessing 'let ' variable before declaration
JS
I found some strange behaviour of JavaScript with passing variables as a parameter to function , here is the snippet : The output is : With variable notWorks everything is clear - function in then ( ) is called when the variable is already cleared . But why if I set this object to a new variable it saves initial value ...
var notWorks = { aa : `` string '' , } function why ( ) { var thisWorks = notWorks ; $ .get ( `` /echo/json '' ) .then ( function ( ) { printVal ( notWorks ) ; printVal ( thisWorks ) ; } ) ; notWorks = { } ; } function printVal ( val ) { console.log ( val ) ; } why ( ) ; Object { } Object { aa : `` string '' }
Why if I set an object to a new variable it saves initial value of the variable ?
JS
I have a code like this : How do I remove .parent.two because it does n't have any child with .yes ? What I 've tried so far and it did n't work :
< div class='parent one ' > < div class='yes ' > < /div > < div class='yes ' > < /div > < div class='yes ' > < /div > < /div > < div class='parent two ' > < div > < /div > < div > < /div > < div > < /div > < /div > < div class='parent three ' > < div > < /div > < div > < /div > < div class='yes ' > < /div > < /div > $ ...
Remove parent if it does n't have a child with specific class
JS
I am using AJAX via jQuery to make a get request . Upon success , I place the result into a div : The content I 'm requesting itself is HTML and has two divs , # article_name and # article_content . After it loads , I check if # article_content has any children . If it does n't , I add a < p > block : This works , unti...
$ .get ( `` content.php '' , function ( result ) { $ ( ' # content ' ) .html ( result ) ; if ( ! $ ( ' # article_content ' ) .children ( ) .length ) { $ ( ' # article_content ' ) .html ( ' < p > ( Click here to enter text ) < /p > ' ) ; } }
Part of jQuery 's callback handling undoes my statement
JS
I have the following code : Both x.subSpells.duration and x.subSpells.quicken equal 1 . Same with y. I want x.subSpells.quicken and y.subSpells.duration to be undefined . If I do the following for the Duration and Quicken definitions , I get the behaviour I want.I think there is a problem with double inheritance . Can ...
function Rune ( ) { this.subSpells = [ ] ; } function Modifier ( ) { this.type = `` modifier '' ; } Modifier.prototype = new Rune ( ) ; function RuneFactory ( effect , inheritsFrom , initialValue ) { var toReturn = function ( ) { } ; toReturn.prototype = new inheritsFrom ( ) ; toReturn.prototype.subSpells [ effect ] = ...
Using a function in Javascript to Generate Noninstantiated Functions
JS
I have above JSON array . I am trying to convert it into a JSON Object asI was able to achieve this in PHP byBut ca n't figure it out in JS .
[ { `` id '' : '' 15 '' , '' heading '' : '' Post1 '' , '' content '' : '' Post 1 Content '' , '' date '' : '' 2016-11-09 08:51:37 '' } , { `` id '' : '' 16 '' , '' heading '' : '' Post2 '' , '' content '' : '' Post 2 Content '' , '' date '' : '' 2016-11-09 08:52:09 '' } , { `` id '' : '' 17 '' , '' heading '' : '' Pos...
How to modify/retransform JSON array structure
JS
Output : So the code on line 4 is being executed after the code on line 8.Does my usage of let have anything to do with this ? EDIT : After reading comments I realised that this might be because of my runtime . Here 's how I see it in Firefox nightly : EDIT 2 : If this is indeed just my runtime , then are there implica...
if ( true ) { let m = `` yo '' ; console.log ( m ) ; } console.log ( m ) ReferenceError : m is not definedyo
JavaScript execution order : why does this conditional execute after the code that follows it ?
JS
I am having some Problems with JavaScript . I have got the following code : The SpecializedControl inherits from the Control class.The addControl function in the Form class just adds the control to an array.The problem is that when I add more than one SpecializedControl , the values in the array are kind of overriden ,...
< html > < head > < title > Test < /title > < script type= '' text/javascript '' > function Control ( ) { var name ; this.setName = function ( newName ) { name = newName ; } ; this.getName = function ( ) { return name ; } ; } function SpecializedControl ( ) { } SpecializedControl.prototype = new Control ( ) ; function ...
JavaScript : Adding inherited class to array does not work
JS
As seen in this SO questionIn this example why is it coded aswill it be ok if I doI am just trying to understand any specific reason for using callAnd also what would be some other scenario where we will have to use Array.prototype.slice.call ( arguments ) ?
Function.prototype.bind = function ( ) { var fn = this , args = Array.prototype.slice.call ( arguments ) , object = args.shift ( ) ; return function ( ) { return fn.apply ( object , args.concat ( Array.prototype.slice.call ( arguments ) ) ) ; } ; } ; args = Array.prototype.slice.call ( arguments ) args = arguments.slic...
Why is array slice method called using `` call '' ?
JS
I have 10 < div > with the same class . I want Only 2 div visible when the page load and after clicking on a load more button the next div should show . This way after click on every load more button the next single hide div should display.I have tried with below code but unable to success.Html Structure is
< script type= '' text/javascript '' > $ ( `` # loadmore '' ) .click ( function ( ) { $ ( `` .design-derection '' ) .one ( `` div '' ) .show ( ) ; } ) ; < /script > < div class='content-block ' > < div class='design-derection ' > < /div > < div class='design-derection ' > < /div > < div class='design-derection ' > < /d...
On click of button div display 1 by 1 ( single at a time )
JS
I am trying to save data using soap Jquery with C # WebMethod But can not save data in SQL Server please help me how can I save data using Soap jquery.I am using IDE Visual Studio 2015 .
< script type= '' text/javascript '' > function SavePersonRecord ( ) { var Name = $ .trim ( $ ( ' # < % =txtName.ClientID % > ' ) .val ( ) ) ; var LName = $ .trim ( $ ( ' # < % =txtlname.ClientID % > ' ) .val ( ) ) ; var Company = $ .trim ( $ ( ' # < % =txtCompany.ClientID % > ' ) .val ( ) ) ; var Messege = `` '' ; if ...
How Can I save Data using Soap Jquery in SQL Server 2012 ?
JS
I 'm trying to understand why javascript is doing something unexpected ( to me ) . Here 's a bit of code that 's purely for example . In other words , I do n't actually want to extend String ( I 'm actually binding to functions and stuff ) . So this is plain javascript with no libraries.And here 's the output in Safari...
var s = 'blah ' ; String.prototype.foo = function ( ) { console.log ( 'this === s : ' , this === s ) ; console.log ( 'this == s : ' , this == s ) ; console.log ( 'typeof this : ' , typeof this ) ; console.log ( 'typeof s : ' , typeof s ) ; console.log ( 'this : ' , this ) ; console.log ( 's : ' , s ) ; } ; s.foo ( ) th...
why does passing a string as `` this '' cause this weirdness ?
JS
All my arrays are trees , one node can only belong to one parent.I want to merge list1 with list2 and get the resultList.I tried many ways , recursive callback , string search & replace and so on , but i still could n't figure it out .
var list1 = [ { id : 'node1 ' , children : [ { id : 'node11 ' , children : [ ] } ] } ] ; var list2 = [ { id : 'node1 ' , children : [ { id : 'node13 ' , children : [ ] } ] } ] ; var resultList = [ { id : 'node1 ' , children : [ { id : 'node11 ' , children : [ ] } , { id : 'node13 ' , children : [ ] } ] } ] ;
how to merge dimensional arrays
JS
I am trying to change the value of an td value with the button that is clicked.. I have tried a couple of ways but none have worked . If user click Show USD button column show only USD values , If user click GBP column should show GBP values . I do n't know this this is correct way to do this . Any help highly apprecia...
$ ( '.btn-usd ' ) .on ( 'click ' , function ( ) { $ ( `` cu-usd '' ) .removeClass ( hide ) ; $ ( `` cu-gbp '' ) .addClass ( hide ) ; } ) ; $ ( '.btn-gbp ' ) .on ( 'click ' , function ( ) { $ ( `` cu-gbp '' ) .removeClass ( hide ) ; $ ( `` cu-usd '' ) .addClass ( hide ) ; } ) ; .hide { display : none ; } < script src= '...
Change table value using jquery
JS
I have a 3D array with objects inside : How to flatten it including removing duplicated id parameter ? I think underscore would be helpful with that
[ [ { id : 1 } , { id : 2 } ] , [ { id : 3 } ] , [ { id : 3 } , { id : 4 } ] ] [ { id : 1 } , { id : 2 } , { id : 3 } , { id : 4 } ]
Flatten 3D array containing objects to 2D removing duplicated objects by it 's parameter
JS
Good evening readers ! I 'm working to a simple shopping cart single page application using react and redux ! That 's the situation : In my component , inside the render method , there is : The result is something like this : I just want to render an accordion filled with the category name , items grouped by category u...
listOfCategories : [ `` Basic '' , `` Hardware '' ] listOfItems : [ { fields : { category : `` Basic '' , name : `` Starter '' , ... } , ... } , { fields : { category : `` Basic '' , name : `` Entertainment '' , ... } , ... } , { fields : { category : `` Hardware '' , name : `` STB '' , ... } , ... } ] render ( ) { ret...
Render products grouped by category
JS
I have a basic list going on , with the HTML structure like this : Then I use some JS to add buttons to delete items , so the end structure is like this : I also have a function to strike through the list elements on click by toggling a CSS class : This works as expected ( e.g . the list item is struck through ) . Howe...
< ul class= '' list '' > { ... } < li class= '' item '' > Ellipse < /li > { ... } < ul class= '' list '' > { ... } < li class= '' item '' > Ellipse < button > Delete item < /button > < /li > { ... } let ul = document.querySelector ( '.list ' ) ; { ... } function markAsDone ( event ) { let target = event.target ; target...
Why does setting the element display property to flex in CSS change the behaviour of the JS onclick event with 'event.target ' ?
JS
My jQuery Script : My jQuery script is quite a large file however I have trimmed it down to the most relevant parts for this question as seen below ; My HTML Structure : QuestionFirst of all , I know how to check where the item is to be moved either from the .Pinned element or the .Standard to the other element via suc...
$ ( document ) .ready ( function ( ) { `` use strict '' ; $ ( document ) .on ( 'click ' , function ( e ) { if ( ( $ ( e.target ) .attr ( 'data-action ' ) ) || $ ( e.target ) .parent ( ) .data ( 'action ' ) ) { if ( $ ( e.target ) .attr ( 'data-action ' ) ) { action = $ ( e.target ) .data ( 'action ' ) ; } else { action...
Finding the correct place to append content
JS
I am trying some unit testing , I created a sandbox with a fake example https : //codesandbox.io/s/wizardly-hooks-32w6l ( in reality I have a form ) So my initial idea was to try to test the multiply function . And did this , which obviously does n't workI get _App.default.handleMultiply is not a functionIs my approach...
class App extends React.Component { constructor ( props ) { super ( props ) ; this.state = { number : 0 } ; } handleSubmit = ( number1 , number2 ) = > { this.setState ( { number : this.handleMultiply ( number1 , number2 ) } ) } handleMultiply = ( number1 , number2 ) = > { return number1 * number2 } render ( ) { const {...
How to test class components in react
JS
Running the following comparison by using jQuery 's `` is '' function will return false , since the DOM elements are n't exactly the same , although visually and functionally they are the same : Using direct comparison of the DOM objects will return false as well.See Running example : http : //jsfiddle.net/6zqwn/5/So ,...
var $ a = $ ( ' < div id= '' test '' href= '' http : //www.google.com '' > < /div > ' ) ; var $ b = $ ( ' < div href= '' http : //www.google.com '' id= '' test '' > < /div > ' ) ; $ a.is ( $ b ) ; //FALSE
Is there a way to compare jQuery objects while ignoring the HTML attributes ' ORDER ?
JS
I am not a regular developer.All I wanted was to add a language translation to select2 ; translated the default src/js/select2/i18n/en.js file contents , created new file with changing labels from English to non-english.Upon submitting the pull request , I see the All checks have failed and below the CI/Linting result ...
Run grunt compile lintRunning `` requirejs : dist '' ( requirejs ) taskError : ENOENT : no such file or directory , open'/home/runner/work/select2/select2/src/js/select2/i18n/en.js'In module tree : select2/coreselect2/optionsselect2/defaultsWarning : RequireJS failed . Use -- force to continue.Aborted due to warnings. ...
All checks have failed due to Warning : RequireJS failed . Use -- force to continue
JS
I 've written the following snippet of code : I expected the function that prints a to be called , but it instead gives a runtime error about calling an undefined value . Why does this happen ?
var f = function ( ) { document.write ( `` a '' ) ; } ; function foo ( ) { f ( ) ; var f = function ( ) { document.write ( `` b '' ) ; } ; } foo ( ) ;
What is going on with JavaScript scope here ?
JS
Getting an unexpected NaN on an Exercise in Eloquent Javascript chapter 4 , but the error is not obvious enough for me to pick up on it . Would someone mind taking a look and pointing out my error ? And here is the Firebug output , displaying that typeof total after the for loop in func sum is indeed number but is then...
/*Write a range function that takes two arguments , start and end , and returns an array containing all the numbers from start up to ( and including ) end . */var numRng = [ ] ; function range ( start , end ) { //var numRng = [ ] ; cntr = ( end - start ) ; for ( i = 0 ; i < = cntr ; i++ ) { numRng.push ( start ) ; star...
Unexpected NaN output after typeof var displays expected numer type
JS
I 'm trying to combine two arrays and most of the answers relate to adding the second array to the end of the first . I need to merge index to index.Here 's example code : The result should be : The above code looks like it should work but does n't . If it can be fixed , or exchanged for better that would be great ... ...
let arr1 = [ 'golf ' , 'hockey ' , 'tennis ' ] ; let arr2 = [ 'player1 ' , 'player2 ' , 'player3 ' ] ; Array.prototype.zip = function ( arr ) { return this.map ( function ( e , i ) { return [ e , arr [ i ] ] ; } ) } ; const arr3 = arr1.zip ( arr2 ) ; console.log ( arr3 ) ; [ 'golf ' , 'player1 ' , 'hockey ' , 'player2 ...
Merging JavaScript arrays based on index without .concat
JS
I have only just started messing up with Javascript inheritance and ca n't get my hed round this one : If I run this code : I expect to have the following `` structure '' in memory : I messed up in the graphic , Bar2 obviously has a value of `` 3 '' for its property `` y '' And happily enough , I can confirm that , by ...
function Foo ( y ) { this.y = y ; } Foo.prototype.x = 1 ; var Bar1 = new Foo ( 2 ) ; var Bar2 = new Foo ( 3 ) ; console.log ( `` Prototype - x : `` , Foo.prototype.x , `` y : `` , Foo.prototype.y ) ; console.log ( `` Bar1 - x : `` , Bar1.x , `` y : `` , Bar1.y ) ; console.log ( `` Bar2 - x : `` , Bar2.x , `` y : `` , B...
About the prototype object and it 's role in Javascript inheritance
JS
I am making a jQuery plugin , and I was wondering if there was a way that I could find the selector that the user uses to apply the plugin . For example , if the user selects this : Then the plugin will return myClass , which can then be used later . Is there a way I can do this ?
$ ( `` .myClass '' ) .pluginName ( ) ;
find selector used jQuery
JS
Hello guys here the problem . I want to perform a different calculation based on the check box . Here is the javascript for calculating the price of the itemthe problem is that i dont know how can i do the else if methodAdvance thank you guys .
< div > COD : < input type= '' checkbox '' id= '' trigger '' name= '' question '' > < /div > < script > $ ( `` # price , # quant , # shipment '' ) .keyup ( function ( ) { if ( +myFunction3 ( ) == '' '' ) { $ ( ' # demo ' ) .val ( 0 ) ; } else if ( $ ( ' # trigger ' ) == '' checked '' ) //this is the problem { $ ( ' # d...
How to change the value of check box when it is checked or unchecked
JS
When I do something like this : The difference in the returned value between ( A ) and ( B ) is explained by the value of x at the time it becomes evaluated . I figure that backstage something like this should happen : But this only holds true if and only if x is evaluated in the same left-to-right order that it was wr...
var x = 5 ; console.log ( x + ( x += 10 ) ) ; // ( B ) LOGS 10 , X == 20console.log ( ( x += 10 ) + x ) ; // ( A ) LOGS 0 , X == 30 TIME -- -- > ( A ) ( x = 5 ) + ( x += 10 = 15 ) = 20 ( B ) ( x += 10 == 15 ) + ( x == 15 ) = 30 var x = 5 ; console.log ( x += 5 , x += 5 , x += 5 , x += 5 ) ; // LOGS 10 , 15 , 20 , 25
Is the order of execution of operations in Javascript guaranteed to be the same at all times ?
JS
I have three ways of making a function and returning it . ( Maybe there is more ? ) but I do n't know the differnce between them and when to use which.Could someone please explain .
var test1 = function ( ) { var funk1 = function ( ) { console.log ( 1 ) ; } var funk2 = function ( msg ) { console.log ( msg ) ; } return { funk1 : funk1 , funk2 : funk2 } } ; var test2 = function ( ) { this.funk1 = function ( ) { console.log ( 1 ) ; } this.funk2 = function ( msg ) { console.log ( msg ) ; } } ; var som...
Three different ways of using javascript functions , but I do n't know the pros and cons for it . Could someone explain the differences ?
JS
I have string that contains numbers and characters . I want to replace the numbers with another value that will give it a css class of someClass.Now I got the code to detect all the numbers in the string and replace it with something else.My question is how do I get the current number match and put it to the new string...
var string_variable ; string_variable = `` 1FOO5,200BAR '' ; string_variable = string_variable.replace ( / ( ? : \d*\ . ) ? \d+/g , `` < span class='someClass ' > '' + string_variable + `` < /span > '' ) ; alert ( string_variable ) ;
replacing numbers in a string with regex in javascript
JS
How to remove all blank Objects from an Object in Javascript?Like thisHow to get result :
const test= { a : ' a ' , b : { } , c : { c : { } } } test= { a : ' a ' }
How to remove all blank Objects from an Object in Javascript?
JS
Hi guys i 'm having a problem . I 'm retrieving some values from a Database and I 'm displaying them in a form for editing . When editing is done the values will sent back to the DB.I want to show a div if a radio with value `` Yes '' is checked and if a radio with value `` No '' is checked i want to show another div.T...
< input type= '' radio '' name= '' longer '' id= '' Yes '' value= '' Yes '' < ? = ( $ info [ 'longer ' ] =='Yes ' ) ? 'checked ' : '' ? > > Yes < input type= '' radio '' name= '' longer '' id= '' No '' value= '' No '' < ? = ( $ info [ 'longer ' ] =='No ' ) ? 'checked ' : '' ? > > No < div id= '' first '' > Show if valu...
Show div1 if radio1 is checked and div2 if radio2 is checked
JS
QuestionLet 's say I have the following class in CSI 'd like to have a class Bar extends Foo whose foo property returned { one : 1 , two : 2 , three : 3 } . Is there a way I can do this in the class definition for Bar where I am only appending three : 3 to the already existing foo property on the superclass Foo ? Use c...
class Foo foo : one : 1 two : 2 class Foo foo : - > one : 1 two : 2 class Bar extends Foo foo : - > _.extends super , three : 3
Is there a way to define an object on the prototype based on the super class value in Coffeescript ?
JS
I 'm using in-browser Javascript , not NodeJS . I have two Uint8Arrays ... Each will have exactly 8 elements that are whole numbers between 0 and 255 . Each array represents a larger number . For example , the first array represents the positive integerMy question is how can I divide d1 by d2 and get a result ? I read ...
var d1 = new Uint8Array ( [ 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 ] ) var d2 = new Uint8Array ( [ 255 , 255 , 255 , 255 , 237 , 49 , 56 , 0 ] ) 0xffffffff
In Javascript ( but not Node ) , how do I divde two Uint8Arrays ?
JS
I 'm trying to loop over a list of views , and for each view retrieve a list of objects associated with that view , using a service call . Each view is being assigned the result of the last call to the function , instead of the result of the function call with its parameters . Debugging output statements in the service...
views.forEach ( ( view : PeriodSummaryView ) = > { view.CategorySummaries = API.getCategorySummariesByPeriod ( view.Period , new Date ( ) ) ; // every view is given the result of the last evaluation of this function view.TotalSpent = this.sumAmounts ( 'Spent ' , view.CategorySummaries ) ; view.TotalBudgeted = this.sumA...
How to return a list of objects from a function inside a loop
JS
I am going to find sequential string of numbers in string which starts from 1 . For example I have this string.Here sequential strings would beHow can I get above result using Javascript efficiently ? The code looks like this . ***note : `` 1 '' itself is not sequential , for example : With any language 's solution wou...
`` 456000123456009123456780001234000 '' `` 123456 '' , `` 12345678 '' , `` 1234 '' findSequential ( `` 456000123456009123456780001234000 '' ) ; //expected output '' 123456 '' , `` 12345678 '' , `` 1234 '' `` 3938139 '' - has no sequence '' 39381249 '' - has `` 12 ''
finding sequential in string using javascript
JS
I have a problem with javascript . I use google api and it contains ajax . The problem here is that , I need to catch values from URL like http : //examplesite.com/index.php ? s=some+values . I need to search values automatically . I try to do this for along time . However , I could n't . How can I do this ? This is my...
< form id= '' searchForm '' method= '' post '' > < fieldset style= '' width : 520 ; height : 68 '' > < input id= '' s '' type= '' text '' name= '' s '' / > < input type= '' submit '' value= '' Submit '' id= '' submitButton '' / > $ ( document ) .ready ( function ( ) { var config = { siteURL : 'stackoverflow.com ' , // ...
Auto Form Post With Url Function
JS
I do n't get how the inner function gets passed the arguments from .sort ( ) method . I know that .sort ( ) passes the values to createComparisonFunction ( ) , but how do they end up in the inner function ? Does it just take any unused arguments from the outer function ? I 'd like to understand that behavior .
function createComparisonFunction ( propertyName ) { return function ( object1 , object2 ) { var value1 = object1 [ propertyName ] ; var value2 = object2 [ propertyName ] ; if ( value1 < value2 ) { return -1 ; } else if ( value1 > value2 ) { return 1 ; } else { return 0 ; } } ; } var data = [ { name : `` Zachary '' , a...
Inner function taking arguments from outer
JS
In first API call I 'm getting an array of IDs to be able to make another API call to grab revenue key/value pairs , then push it back to the main object ( as it does n't have it by default ) .Data I 'm getting is in the following format [ { … } , { … } ] . So instead of an array of objects I 'm trying to get an array ...
const mainURL = `` https : //api.themoviedb.org/3/discover/movie ? api_key=2339027b84839948cd9be5de8b2b36da & language=en-US & sort_by=revenue.desc & include_adult=false & include_video=false & page= '' ; const movieBaseURL = `` https : //api.themoviedb.org/3/movie/335 ? api_key=2339027b84839948cd9be5de8b2b36da & langu...
Object.assign ( { } , item ) to merge objects into one does n't work
JS
I created the next code : This code should add all values from each input in array and output then on the screen . I get only the number of inputs , but how to get the values from each input ?
var b = document.getElementById ( `` btn '' ) ; b.addEventListener ( 'click ' , function ( ) { var a = document.createElement ( `` input '' ) ; document.getElementById ( 'container ' ) .appendChild ( a ) ; } ) ; var c = document.getElementById ( 'btn2 ' ) ; c.addEventListener ( 'click ' , function ( ) { document.queryS...
Add inputs values in array
JS
Can anyone explain this behaviour ?
var array = [ 1,2,4 ] ; array+1 //gives ' 1,2,41 ' .
Why does adding an array to number return a string ?
JS
I 'm building simple web template from scratch.I use old style jquery to make a hover on navbar to show list < li > , but it is working only on About us column and is n't working on Product column.What is wrong ? How should I do it ? HTML pageCSS
< ! DOCTYPE html > < html > < head > < meta charset= '' utf-8 '' / > < title > Template < /title > < meta name= '' viewport '' content= '' width=device-width '' / > < script src= '' < ? php echo base_url ( ) ; ? > js/jquery-3.0.0.min.js '' > < /script > < link rel= '' stylesheet '' type= '' text/css '' href= '' < ? php...
jQuery - Navbar hover did not show
JS
I 'm building a news feed using React and moment.js . Using .map I 'm rendering items with a title and content . I 'd like to check if an item was posted in the same year and month as another item . If this is the case I want to hide the second items title.Please see my fiddleCurrently my code renders this : March 2018...
let monthNodes = [ ... document.querySelectorAll ( '.months ' ) ] ; let months = [ ] monthNodes.map ( month = > { months.push ( month.className ) } ) const count = names = > names.reduce ( ( a , b ) = > Object.assign ( a , { [ b ] : ( a [ b ] || 0 ) + 1 } ) , { } ) const duplicates = dict = > Object.keys ( dict ) .filt...
Checking if items within mapped array share values
JS
I 'm writing an app to learn TypeScript . It works fine in Chrome , but I have a problem when running in Edge . I 've got this method : I 'm seeing that , sometimes , diff IS a Vector2D as opposed to being an instance of a Vector2D . Obviously , when this happens , any operation on it results in a Object does n't suppo...
set position ( pos : Point ) { const diffAsPoint = pos.minus ( this.canvasPos ) ; let diff : Vector2D = diffAsPoint.toVector2D ( ) ; // < -- - this line if ( diff instanceof Vector2D ) { console.info ( `` is a vector ! `` ) ; } else { console.info ( `` not a vector ! `` ) ; } toVector2D ( ) : Vector2D { return new Vect...
Why does my TypeScript sometimes give me a instance and other times gives me a class ?
JS
I 'm new to javascript and still coming to terms with the language 's nuances.I have a piece of code where I have to check a set of conditions on a particular variable . Is there a better way to do this conditional check , like say : if a is one of ( `` DOMAIN_SERIAL '' , `` MAIN_DOMAINNAME '' , `` DOMAIN_REFRESH '' ) ...
if ( a== '' MAIN_DOMAINNAME '' || a== '' DOMAIN_SERIAL '' || a== '' DOMAIN_REFRESH '' || a== '' DOMAIN_RETRY '' || a== '' DOMAIN_EXPIRE '' || a== '' DOMAIN_NEGTTL '' || a== '' MAIN_NS '' ) {
Better method of checking a bunch of conditions
JS
I have this for exemple : And this two line of jQuery : Returns : But ReturnsWhy the line 2 , return the HREF attribute of the anchor IF 'this ' argument add a `` string '' ? The jQuery docs says if filter have an function argument , the `` this '' is the current DOM element
< div id= '' example '' > < a href= '' http : //www.google.com/ # 1 '' > Hello < /a > < a href= '' http : //www.google.com/ # 4 '' > Hello < /a > < /div > jQuery ( `` a '' ) .filter ( function ( ) { console.log ( `` '' +this+ '' '' ) } ) ; http : //www.google.com/ # 1 http : //www.google.com/ # 4 jQuery ( `` a '' ) .fi...
Why `` this '' argument in jQuery returns href with anchors
JS
When I open Chrome developer tools , open this web page , and take a snapshot , the size is 2.1MB.When I click on one of the buttons , all of them and their div are removed . If I then take another snapshot , the size is 1.6MB.So is it the case that when using Chrome developer tools and taking snapshots , there will al...
< ! DOCTYPE HTML PUBLIC `` -//W3C//DTD HTML 4.01//EN '' `` http : //www.w3.org/TR/html4/strict.dtd '' > < html > < head > < script type= '' text/javascript '' > var onLoadFunc = function ( ) { for ( var x=0 ; x < 30000 ; x++ ) { var button = document.createElement ( `` input '' ) ; button.type = `` button '' ; button.v...
Why does removing almost all objects from dom not result in lower memory ?
JS
I use chart.js with React . My question is how to show the month label ( MMM ) only once per month ? The chart currently has labels : [ May 15 , May 18 , May 21 , May 24 , ... ] As result I want to get : [ May 15 , 18 , 21 , 24 , 27 , 30 , Jun 2 , 5 , ... ] CodeSandboxLine Chart :
import React from 'react'import { Line } from 'react-chartjs-2'import date from 'date-and-time'const startDate = new Date ( 2020 , 4 , 15 ) //===fake data===const json = ' { `` responses '' : [ { `` rows '' : [ { `` values '' : [ `` 1 '' ] } , { `` values '' : [ `` 0 '' ] } , { `` values '' : [ `` 0 '' ] } , { `` value...
Format chart.js x labels
JS
The standard HTML 5 form label wants an ID to link the label to the input.As most JS developers know , using IDs leaks globals - in this case , window.male and window.female are created.How can I use form labels without creating globals ?
< form > < label for= '' male '' > Male < /label > < input type= '' radio '' id= '' male '' / > < label for= '' female '' > Female < /label > < input type= '' radio '' id= '' female '' / > < /form >
Is it possible to use HTML5 form labels without leaking globals ?
JS
In JavaScript , we can get a number representing the current date/time like so : A slightly shorter hand way of doing this might be : The most compact way of doing this is reflected in the following code : ( See them working here : http : //jsfiddle.net/es4XW/2/ ) Now , when you search through the source code of the Go...
var dt = new Date ( ) ; var e = dt.getTime ( ) ; var f = ( new Date ( ) ) .getTime ( ) ; var g = +new Date ; //11 bytes shorter
Why do Google not optimize Date/Time construction in their front-page Javascript
JS
I 'm new to Javascript and I am trying to build something relatively simple.I have an HTML file with the following div in it : What I want to do is make a Javascript function which takes the text inside this div , splits it into words and shows only as many words as I choose . Also I want to add a `` see more '' link a...
< p id= '' textArea '' class = `` more '' > < ! -- random_text -- > < /p > function expandContent ( ) { var showChar = 30 ; var ellipsesText = `` ... '' ; var moreText = `` ( read more ) '' ; var lessText = `` ( read less ) '' ; $ ( '.more ' ) .each ( function ( ) { var $ this = $ ( this ) ; var fullText = $ this.text ...
Javascript link vanishing after first click
JS
here is a jsfiddle I made to show you what I 'd like help with.Need help with updating select box valuesI 've tried using 3 for loop constructs to update my drop down box , but my bad Javascript skills do n't let me achieve this.When I switch to millivolts in the drop down box , the values for Current and Resistance sh...
var units = [ [ 'Volts ' , 1 ] , [ 'Millivolts ' , .001 ] , [ 'Microvolts ' , 0.000001 ] ] ; var selectors = document.querySelectorAll ( '.Voltage ' ) ; for ( var i = 0 ; i < units.length ; i++ ) { for ( var j = 0 ; j < selectors.length ; j++ ) { var option = document.createElement ( 'option ' ) ; option.value = units ...
Bad Javascript Coding and Drop Down Boxes
JS
I have an object like so : I am now looping through this object and searching for the object keys that are true , like so : How do I know when I have reached the last loop pass where one of the keys is true ?
var obj = { thing_1 : false , thing_2 : false , thing_3 : true , thing_4 : false , thing_5 : true } for ( value in obj ) { if ( obj [ value ] === true ) { // do something } }
How to know you 're at the last pass of a for loop through object ?
JS
I have the following layout on a page : On the left I have the desktop ( lg ) version , And on the right the reordering that I want to have on the small devices.With this code : I get a Problem with the desktop view : see printscreen : Any proposals to fix that problem and to show the description element ( 3 ) direct u...
< div class= '' row '' > < div class= '' col-sm-6 col-sm-push-6 '' > < div class= '' alert alert-danger '' > < h1 > Lorem Ipsum ( 2 ) < /h1 > < br > Rostfreie Bohrbefestiger für Stahl- und Aluminiumunterkonstruktionen < /div > < /div > < div class= '' col-sm-6 col-sm-pull-6 '' > < div class= '' alert alert-info '' > Im...
Twitter bootstrap reorder elements on small devices
JS
I have used the following jquery code to hide and show an element on a click event of a buttonThere are plenty of examples on setting the display to block , inline etc and also use of jquery hide and show . The above code i used on my page works fine but i do not know if its correct use of the display . Can anyone plea...
< div id='testDiv ' > Test < /div > $ ( ' # testDiv ' ) .css ( 'display ' , 'none ' ) ; $ ( ' # testDiv ' ) .css ( 'display ' , '' ) ;
jquery css display property set to `` '' is it valid usage ?
JS
I found strange behavior ( tested at Chrome ) and that 's ok -- ok as in documentationButIt does n't use callback ( no actions , debugger inside does n't work etc . ) . Why ? ? Syntax new Array ( arrayLength ) should create array with given length . And it does . But what with .map ?
[ 1,2 ] .map ( function ( ) { console.log ( arguments ) ; } ) // [ 1 , 0 , Array [ 2 ] ] // [ 2 , 1 , Array [ 2 ] ] // [ undefined , undefined ] ( new Array ( 20 ) ) .map ( function ( ) { console.log ( arguments ) ; } ) // [ undefined × 20 ]
( new Array ( x ) ) .map stranges
JS
I 've been trying to solve this problem for a week now and it seems basic , so maybe I 'm missing something.I want to have a div centered on the screen ( or its container ) , and then insert a second div to the right of it , so that afterwards the two of them are centered ( space on each side is equal ) . Inserting the...
.container { width:100 % ; text-align : center ; } .inside { border : solid 1px black ; width:100px ; height:100px ; display : inline-block ; } $ ( document ) .ready ( function ( ) { $ ( `` # add '' ) .click ( function ( ) { $ ( `` .container '' ) .append ( `` < div class='inside ' > < /div > '' ) ; } ) ; } ) ; < div c...
Insert inline element and animate shift to left
JS
I have data for tasks that were recorded with a time sheet app . I 'm trying to parse the breaks for each task.An example break string attached to a task can look like this:1:19pm – 10:33pm ate tacos 10:35pm – 11:38pm 12:40am – 1:24am took anapI need to group this into time stamps with their associated descriptions . T...
\d { 1,2 } : \d { 2 } [ ap ] m\s–\s\d { 1,2 } : \d { 2 } [ ap ] m
Grouping timestamps with descriptions
JS
Imagine we define a new object like this : This should define a new `` Hidden Class '' with these two properties.Now imagine I define a new class using ES6 class syntax.and I create a new object from it.Now the question : Is the `` Hidden Class '' of the bar going to be the same as the Hidden Class of foo ? Because wha...
const foo = { number1 : 1 , number2 : 2 } class Numbers { constructor ( ) { this.number1 = 1 this.number2 = 2 } } const bar = new Numbers ( )
Can JavaScript optimize this object ?
JS
I have a selectedItem object in Angular , it contains other objects and arrays . I create a deep copy using a JSON trick : Then I use editableItem model in inputs , change some values inside . selectedItem does n't change . Then I want to send via PATCH all the changes made , but not the fields which were not changed ....
$ scope.editableItem = JSON.parse ( JSON.stringify ( $ scope.selectedItem ) )
How to traverse JS object and all arrays and objects inside to compare it with its copy ?