lang stringclasses 4
values | desc stringlengths 2 8.98k | code stringlengths 7 36.2k | title stringlengths 12 162 |
|---|---|---|---|
JS | I 'm making a system for calculating road taxes in the netherlands , there for i got a few JS arrays ( where the data is in ) which i 'm parsing with JS ( all at the same time , because it 's the same format of data ) , then passing it to PHP as JSON format using the XMLHttpRequest object.For this i first made this dat... | var roadTaxData = { provinceWeightFuelPricesData : { personen_auto : { noord_holland : dataNoordHolland , zeeland : dataZeeland //TODO : Add all the provinces with it 's data to the personen_auto object } , kampeer_auto : { noord_holland : dataNoordHolland2 , zeeland : dataZeeland2 } } } /* Loop through all the specifi... | Parsing JS array with JS and then passing it to PHP |
JS | In Firefox I received a weird syntax error , as this is not trivial , and an interesting syntax error I 'd like to post here because I do n't know it 's happening.Should file this as a bug report ? I was testing some scripts from here : hereIt gave me a syntax error . SyntaxError : invalid label at line 5.And this one ... | app.directive ( `` alertable '' , function ( ) { return { restrict : `` A '' , link : function ( scope , element , attrs ) { element.bind ( `` click '' , function ( ) { alert ( attrs.message ) ; } ) ; } } ; } ) ; app.directive ( `` alertable '' , function ( ) { return { // fix ? ? ? restrict : `` A '' , link : function... | Weird javascript syntax error |
JS | Local storage ceases to work when I try to extend it to include contentEditable . Local storage ceases to work when I try to extend it to include contentEditable . The following is the link to the CodePen : https : //codepen.io/zanderbush/pen/WNwWbWe . Any help is appreciated.Alone , this works.However , when I add the... | var app = angular.module ( 'TodoApp ' , [ `` LocalStorageModule '' ] ) ; app.controller ( 'TodoController ' , function ( $ scope , localStorageService ) { if ( ! localStorageService.get ( `` taskListActive '' ) ) { $ scope.tasksActive = [ { text : `` Do me next '' , priority : 1 , complete : false } , { text : `` I 'm ... | Angularjs : Local storage contenteditable not saving |
JS | in my javascript program I have a function ( not in my reach to edit ) that returns a string or an array.So I either have the output `` one '' or [ `` one '' , `` two '' ] I would like the output to alway be an array , so if it returns one string `` one '' I would like to have it as [ `` one '' ] .What is the most easy... | var arr = aFunction ( ) .split ( ) ; | How to convert array or string to array in JavaScript ? |
JS | Looking at some JavaScript libraries and other people 's code I 've seen two common patterns , I do n't know if there is a difference or advantage in using one of them . The patterns look sort of like this:1.2.Are this patterns the same or do one of them has an advantage or different use than the other ? Thanks in adva... | var app = ( function ( ) { // Private vars // Module var obj = { prop : `` '' , method : function ( ) { } } ; return obj ; } ) ( ) ; ( function ( ) { // Private vars // Module var obj = { prop : `` '' , method : function ( ) { } } ; window.app = obj ; } ) ( ) ; | Is there any difference between this two JavaScript patterns ? |
JS | Using JavaScript , is it permissible to use a function as a prototype , e.g.or is it required to useand more importantly , does it make an important difference ? | function Foo ( ) { } Foo.prototype = function ( ) { } Foo.prototype = { } ; | Using function as prototype |
JS | I have a javascript file in my HTML page that is included like so : yet in the chrome network debugger , when i look at what is loaded , it has : This is problematic as im not wishing this particular file to bypass caching.If it makes a difference , the html file is being loaded through an AJAX call.The value for the f... | < script type= '' text/javascript '' src= '' javascript\pages\page.js '' > < /script > http : //localhost:12639/javascript/pages/page.js ? _=1556081859333 $ .ajax ( { url : 'process.php ' , type : 'POST ' , datatype : `` json '' , async : true , data : { //some data } , error : function ( jqXHR , textStatus , errorThro... | Why does Chrome add a query string parameter after included Javascript file ? |
JS | I 'd like to be able to get a list of functions on different JavaScript objects , but specifically String and other primitives . I thought I would be able to somehow use String.prototype and magically get a list of the functions in the prototype but no dice . Any ideas ? I also tried using underscore . For example ... ... | _.functions ( `` somestring '' ) ; | List of functions in the prototype |
JS | I want to make a progress bar on my website , which tracks execution of a PHP script.The PHP script makes a bunch of connections with Google API and stores the data it receives in the database . Sometimes the process can take a minute.The PHP script is located in ajax/integrations-ajax.php file and launched by GET AJAX... | $ ( ' # link ' ) .on ( 'click ' , function ( ) { var interval = setInterval ( trackStatus , 1000 ) ; $ .getJSON ( 'ajax/integrations-ajax.php ' , { action : 'link ' } ) .done ( function ( json ) { if ( json.result == true ) { showMessage ( 'The account is successfully linked . ' , 'success ' ) ; } else { showMessage ( ... | Is there a possibility to receive several AJAX responses from PHP server simultaneously ? |
JS | I 've been going through some of gmails javascript ( writing an extension ) and I 've seen ( 0 , _.ab ) ( a ) , or variations , all over the places . What does this achieve ? I 've tried some tests such asHowever I ca n't work out why they would n't just call a ( 1,2,3 ) directly . Does calling it using ( 0 , a ) have ... | function a ( a , b , c ) { console.dir ( a+b+c ) ; } ( 0 , a ) ( 1,2,3 ) | What is meant by ( 0 , somefunc ) ( args ) |
JS | I have a sorted , static list to display with KO , and wanted to show category headers whenever the category changed ( since the list is sorted by category ) . I 'm still genning up on KO , is this the `` KO '' way to do this , or is there a better approach ? In particular the syntax to access the previous item in the ... | < table > < tbody data-bind= '' foreach : items '' > < ! -- ko if : $ index ( ) === 0 || $ parent.items ( ) [ $ index ( ) - 1 ] .category ( ) ! == category ( ) -- > < tr class= '' category '' > < td colspan= '' 2 '' data-bind= '' text : category '' > < /td > < /tr > < ! -- /ko -- > < tr > < td data-bind= '' text : item... | Adding category rows based on matching item properties |
JS | This is purely an educational question.I 'm working on a new version of a web app that the company I 'm working for had made earlier . when re-writing the math , I came across this : Thinking there was no purpose for the `` -0 '' , I removed it . But when I tried the calculations , the numbers were waaayyyyyy off . The... | document.getElementById ( `` estResidual '' ) .value-0 ; | Javascript : what is `` - 0 '' doing ? |
JS | I have a two column red/black grid 50/50 % and height 100 % and had a script to randomize the appearance of both when loading the page , so left or right . I changed the code behind the two column grid a bit going from relative position and float left of right to a fixed and absolute position . This has to do because o... | // Random red & black //window.addEventListener ( 'load ' , function ( ) { // This is a ternary operator , which is just a shorthand way to // do an if/else statement . This basically says , if the random number // is less than .5 , assign `` left '' to the scenario variable . // if it is greater ( or equal to ) , assi... | Randomly add class to two divs |
JS | I cam trying to check to see if an author is in mongo before I save the author . When I run my first rss document through the create author function , all of the authors are saved in the DB - even if they have authored two items in the feed . What 's strange is that if I run the feed through again , mongoose seems to b... | function insertFeedItems ( feedItems , newFeedID , callback ) { feedItems.forEach ( ( item ) = > { let firstName = item.author.substr ( 0 , item.author.indexOf ( ' ' ) ) ; let lastName = item.author.substr ( item.author.indexOf ( ' ' ) + 1 ) ; authorController.createAuthorInternally ( firstName , lastName , function ( ... | Mongoose is saving documents even if I check to see if the document already exists |
JS | I have been working on JavaScript / JQuery code which allows arrow key movement between input boxes ( yes , I am aware this breaks standard UI ) .It works by by looping through each element and finding the closest in each direction ( left , right , up and down ) .ExampleP1 : ( 0 , 0 ) , P2 : ( 1 , 0 ) , P3 : ( 0 , 2 ) ... | Up 1 - > 3 2 - > 3Right 1 - > 2Down 3 - > 1Left 2 - > 1 function arrowKeyNavigation ( elements ) { // Get the position of each element . var elementOffsets = [ ] ; elements.each ( function ( key , element ) { elementOffsets [ key ] = $ ( element ) .offset ( ) ; } ) ; // Find the closest point in each direction and stor... | Finding inaccessible points on a 2D plane |
JS | I am just wondering why this jQuery wo n't work : So as you can see I am trying to get the height of multiple elements and store them all within my variable . I 'd expect jQuery to add all of the elements heights together to create a final value however when I console.log the variable hdr I get the height of the first ... | hdr = $ ( '.header-wrapper , # top-bar , # new-showroom-header ' ) .height ( ) ; | Selecting Multiple Elements height ( ) ; |
JS | I am trying to execute following array ( avoid callbackHell ) of functions ( sync/async ) , in a sequential order , implementing function runCallbacksInSequence ( I need to implement my own function to understand how callbacks work and avoid using Async.js ) .Here is what I have so far . The function runCallbacksInSequ... | function first ( cb ) { setTimeout ( function ( ) { console.log ( 'first ( ) ' ) ; cb ( null , 'one ' ) ; } , 0 ) ; } function second ( cb ) { setTimeout ( function ( ) { console.log ( 'second ( ) ' ) ; cb ( null , 'two ' ) ; } , 100 ) ; } function third ( cb ) { setTimeout ( function ( ) { console.log ( 'third ( ) ' )... | How to handle a duplicate function call from the arrays of function ? |
JS | I 've accomplished adding multiple keywords to the filter , but they work on items in the list containing both keywords . I would like to create a filter where any item in the list can match either or of the keywords . eg : Search Input : Red GreenResult : Red GreenHere is my JQuery search function that allows multiple... | < input id= '' myInput '' type= '' text '' placeholder= '' Search any keywords '' > < button id= '' mySearchBtn '' > search < /button > < ul > < li > Red < /li > < li > Green < /li > < li > Blue < /li > < /ul > $ ( `` # mySearchBtn '' ) .click ( function ( ) { var value = $ ( ' # myInput ' ) .val ( ) .toLowerCase ( ) ;... | Filter a list with jQuery using multiple keywords and allowing multiple results |
JS | Say I have three arrays depicting some names , number of books read and how awesome these people [ in names ] are : I 'm trying to use .reduce ( ) to bring them together to create an array of objects containing the relevant index in each array , but I am failing miserably : I got it with reduce as well : | let names = [ `` Mary '' , `` Joe '' , `` Kenan '' ] ; let numberOfBooks = [ 2 , 1 , 4 ] ; let awesomenessLevel = [ `` pretty cool '' , `` meh '' , `` super-reader '' ] ; let people = [ { name : `` Mary '' , noOfBooks : 2 , awesomeness : `` pretty cool '' } , { name : `` Joe '' , noOfBooks : 1 , awesomeness : `` meh ''... | Combine several arrays into an array of objects in JavaScript |
JS | My component seems to enter an endless loop and I can not find the reason . I am using the useEffect and useState hooks but that is not it . To anyone wanting to tag this as duplicate : Please read the issue carefully . This endless re-render loop scenario only happens if : The mouse is moved too fastA user clicks anyt... | const App = ( ) = > { return ( < MouseProvider > < Component / > < /MouseProvider > ) } const Component = props = > { const [ mouse , setMouse ] = useState ( { } ) const callback = data = > { setMouse ( { x : data.x , y : data.y } ) } useMouseTracker ( callback ) return ( < div > { ` x : $ { mouse.x } y : $ { mouse.y }... | React infinite rerender , useEffect issue , no set state triggered |
JS | Update ( Mar 2nd , 2020 ) It turns out that the coding in my example here was structured in just the right way to fall off a known performance cliff in the V8 JavaScript engine ... See the discussion over on bugs.chromium.org for the details . This bug is now being worked on and should be fixed in the near future.Updat... | const makeJuliaXStepFn = mandelXCoord = > ( x , y ) = > mandelXCoord + diffOfSquares ( x , y ) const makeJuliaYStepFn = mandelYCoord = > ( x , y ) = > mandelYCoord + ( 2 * x * y ) const juliaCalcJS = ( cvs , juliaSpace ) = > { // Snip - initialise canvas and create a new image array // Generate functions for calculatin... | Can anyone explain this unexpected V8 JavaScript performance behaviour ? |
JS | I am currently following a javascript course and am having issues understanding what is happening behind the scenes in javascript in one of the examples ( see code below ) .I understand most of the code and understand why the output logged is - > [ false , true , true ] . However there is one part which is driving me n... | function mapForEach ( arr , fn ) { var newArr = [ ] ; for ( var i = 0 ; i < arr.length ; i++ ) { newArr.push ( fn ( arr [ i ] ) ) } ; return newArr ; } var arr1 = [ 1 , 2 , 3 ] ; var checkPastLimitSimplified = function ( limiter ) { // < -- -- CONFUSED return function ( limiter , item ) { return item > limiter ; } .bin... | Hard time understanding javascript example |
JS | http : //jsfiddle.net/3GTtF/2/Why does var whatIsSecondValue = 4 instead of '4text5'Why does var whatIsInputValue = '45 ' instead of 45 | < ul > < li class= '' first '' value= '' 45 '' > fortyfive < /li > < li class= '' second '' value= '' 4text5 '' > 45 < /li > < /ul > < input value= '' 45 '' > var whatIsValue = $ ( '.first ' ) .val ( ) ; // = 45 typeof = numbervar whatIsSecondValue = $ ( '.second ' ) .val ( ) ; // = 4 typeof = numbervar whatIsInputValu... | Why does attribute value of input = text , but attribute value of li = number ? |
JS | What 's the proper way of handling line feeds on Windows , Mac and Linux . Let 's say I have a simple web app that has a textarea and I need to do a string split every new line . Is it safe to convert \r\n and \r to \n before processing the content of the textarea , or do I need to detect what OS is the user is on and ... | var content = $ ( 'textarea ' ) .val ( ) ; content = content.replace ( /\r\n|\r|\n/gm , `` \n '' ) ; content = content.split ( `` \n '' ) ; // Do Something content = content.join ( `` \n '' ) ; // Update content $ ( 'textarea ' ) .val ( content ) ; | How to handle \n , \r and \r\n on different operating systems ? |
JS | I 'm using javascript to do a verification if an input field is empty this way : It works well , but I wonder if it 's redundant to use both conditions . Do you know it ? | if ( $ ( `` # nu_username '' ) .val ( ) == null || $ ( `` # nu_username '' ) .val ( ) == `` '' ) { do action ... } | javascript verification of empty or null ( is it correct ? ) |
JS | In DOM , is it OK to refer to an element 's attributes like this : ? My deep respect for objects and their privacy , and my sense that things might go terribly wrong if I am not careful , makes me want to do everything more like this : Is it really necessary to use those accessor methods ? Of course it may be more or l... | var universe = document.getElementById ( 'universe ' ) ; universe.origin = 'big_bang ' ; universe.creator = null ; universe.style.deterministic = true ; var universe = document.getElementById ( 'universe ' ) ; if ( universe.hasAttribute ( 'origin ' ) ) then universe.origin = 'big_bang ' ; etc ... | In DOM is it OK to use .notation for getting/setting attributes ? |
JS | I have an array that contains unique strings of day names . The day names will be in random order . - eg : I want to use javascript to sort that array so that it will be in ascending order.Can anybody suggest the best way to do that ? Thank you | [ `` Sun 10am '' , `` Sat 4pm '' , `` Sat 10am '' , `` Wed 3pm '' , `` Sun 4pm '' ] [ `` Wed 3pm '' , `` Sat 10am '' , `` Sat 4pm '' , `` Sun 10am '' , `` Sun 4pm '' ] | Sort array of days in ascending order |
JS | I have a piece of code which includes this : In Chrome 26 : In Firefox 21 : Why does this error occur ? I guess the error has to be in the following function . The full source is on GitHub.edit : Only the complete example is still online.Any recommendations for use of JavaScript are also welcome ( I 'm new to JavaScrip... | var clusterCenters = [ { `` x '' : 1 , '' y '' : 1 } , { `` x '' : 10 , '' y '' : 10 } ] ; console.log ( clusterCenters ) ; function getKMeansInfo ( k , mouseX , mouseY ) { // choose cluster centers var clusterCenters = [ { `` x '' : 1 , '' y '' : 1 } , { `` x '' : 10 , '' y '' : 10 } ] ; console.log ( clusterCenters )... | How can a number in a dictionary in an array be NaN directly after I inserted 1 ? |
JS | I 'm using a BoxElement from blessed to display a chat history.Sentences are added using pushLine . For clarity , days are divided by lines ( another string added using pushLine ) . Each line is as wide as the parent BoxElement.If the TUI is resized however , the line no longer fits.I have 2 questions : How can that li... | /** * Example.ts */import * as blessed from 'blessed ' ; const screen = blessed.screen ( { smartCSR : true , title : 'Chatr ' , dockBorders : true } ) ; const chatBox = blessed.box ( { parent : screen , title : 'Chatbox ' , top : 'top ' , left : 'center ' , height : '100 % ' , width : '100 % ' , border : { type : 'line... | Drawing a line that 's always as wide as its parent BoxElement ? |
JS | I have this regexp that matches correctly everything I need ( all the email addresses NOT inside a link ) : Unfortunately , since javascript does not support lookbehind , it does not work on my web app.Is there a solution for that ? | / ( ( ? < ! mailto : |=| [ a-zA-Z0-9._ % +- ] ) [ a-zA-Z0-9._ % +- ] + @ [ a-zA-Z0-9.- ] +\. [ a-zA-Z ] { 2,64 } ( ? ! [ a-zA-Z ] | < \/ [ aA ] > ) ) / | Regexp lookbehind javascript |
JS | right now I have : But I think this could be done better ... | if ( breadCrumbArr [ x ] ! == 'NEBC ' & & breadCrumbArr [ x ] ! == 'station : |slot : ' & & breadCrumbArr [ x ] ! == 'slot : ' & & breadCrumbArr [ x ] ! == 'believe ' ) { // more code } | What is a better way of testing if a string does n't equal a bunch of stuff ? |
JS | I 've never seen it used like this before : Is this better ? | < script src= '' { { file.name_js } } '' > < /script > | What is this script tag ? |
JS | I wish to achieve this effect : where a draggable will disappear below the edges of the container div.I am not sure in which direction to head . At first I thought I should use css z-index but so far unsuccessful . Is there a simple way to achieve it ? I intend to use it with jsPlumb but I do n't think my question is l... | jsPlumb.bind ( `` ready '' , function ( ) { jsPlumb.setContainer ( `` conteneur '' ) ; jsPlumb.draggable ( document.getElementById ( `` item1 '' ) , { } ) ; console.log ( document.getElementById ( `` item1 '' ) ) ; } ) ; # master { background : orange ; position : relative ; z-index : 21 ; padding : 20px ; } # conteneu... | How to make elements disappear under parent < div > border |
JS | I have a problem when get item in sub array and put back to main array by javascript.I have array like this : I want to get result like this : [ '1595 ' , '8886 ' , '1112 ' ] But when I use this code : Result : [ '1595,8886 ' , '1112 ' ] Can someone help me ? | var array_demo = [ [ '1st ' , '1595 ' , '8886 ' ] , [ '2nd ' , '1112 ' ] ] array_demo.map ( function ( i ) { return i.slice ( 1 ) .join ( ) ; } ) ; | Get item in sub array and put back to main array |
JS | This is a rather fundamental question but im looking for an optimal solution.I have 2 javascript String arrays . Lets say Since `` Stark '' is repeated , i want to remove it from array A and my result should be ( with ordering preserved ) I dont really care for the second array B . Is there something in core javascript... | A : [ `` Stark '' , `` Targaryen '' , `` Lannister '' , `` Baratheon '' ] B : [ `` Greyjoy '' , `` Tyrell '' , `` Stark '' ] A : [ `` Targaryen '' , `` Lannister '' , `` Baratheon '' ] | Remove Strings from one Array if present in another |
JS | I am trying to store the numbers that are divisible by three in the threes array . How is this done ? | var numbers = [ 1,2,3,4,5,6,7,8,9 ] ; var threes = [ ] ; var iLoveThree = function ( numbers , threes ) { for ( i in numbers ) { if ( i.value % 3 == 0 ) { threes.push ( [ i ] ) ; console.log ( threes ) ; } } return threes } ; iLoveThree ( ) ; | How to store divisible number in a new array with javascript |
JS | I 've used a html canvas to create this line : I want the loops in the line filled , so that it looks like this : However when I fill this it simply turns into : I did try using paths , it was the exact same result , just with a line connecting the start to finish.Abstraction of code : How can I get my desired result a... | var canvas = $ ( `` canvas '' ) [ 0 ] , ctx=canvas.getContext ( `` 2d '' ) ; ctx.moveto ( 0,0 ) ; // code to stroke path of mouse cursor ; | How can I fill enclosed shapes in a line ? |
JS | I am trying to find the correct selector to be able to change the background to blue if any Hello cell is clicked , but not if Goodbye is clicked . Adding a class to the Hello cells is a possible option , but not preferred.I have tried : and those dont work . attached a fiddle.Fiddle | $ ( function ( ) { $ ( ' # myTable td ' ) .click ( function ( ) { $ ( ' # myTable ' ) .addClass ( 'unfocused ' ) ; } ) ; } ) ; .unfocused { background-color : blue ; } < script src= '' https : //ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js '' > < /script > < table id='myTable ' > < tr > < td > Hello < /td >... | Jquery selector all cells in table except |
JS | Trying to learn Elm with a background in JS and little experience in strongly- and statically-typed languages , I find that the major difficulty revolves around the type syntax ( and what types are useful for in Elm generally ) . Unfortunately , I do n't find the docs very helpful in this respect.If I take the simple e... | type Msg = Increment | Decrement view model = div [ ] [ button [ onClick Decrement ] [ text `` - '' ] , div [ ] [ text ( toString model ) ] , button [ onClick Increment ] [ text `` + '' ] ] | Understanding types in Elm |
JS | I am just starting to learn typescript/Angular having come from a c++/java background having never touched any web development stuff before . I wrote a small piece of code with some FormControls and someone made a suggested improvement that I do n't understand.The code is as follows : I 've been told that I should chan... | this.myFormData = { ... data } ; this.myForm.controls [ 'name ' ] .setValue ( this.myFormData.name ) ; this.myForm.controls [ 'address ' ] .setValue ( this.myFormData.address ) ; this.myForm.controls [ 'age ' ] .setValue ( this.myFormData.age ) ; this.myForm.controls [ 'gender ' ] .setValue ( this.myFormData.gender ) ;... | Over using 'this ' in typescript |
JS | It pains me to ask such a basic question , but I 'm at my wits ' end.SituationI 'm working on a 32-bit Windows 7 machine , running Firefox 34.0.5.I have a trivial Firefox extension in directory C : \Projects\CloudGem\plugin.The file structure is as follows : All other plugins , excepting some FF developer plugins , are... | window.addEventListener ( `` load '' , function ( ) { setInterval ( function ( ) { console.log ( `` Cloudgem service started ( 2 ) . '' ) ; } , 2000 ) ; } , false ) ; console.log ( `` Cloudgem service started ( 1 ) . '' ) ; < ? xml version= '' 1.0 '' encoding= '' UTF-8 '' ? > < ! DOCTYPE overlay > < overlay id= '' cgem... | Why does my simple Firefox extension now refuse to run ? |
JS | I 'm using multer-s3-transform , which allows me to manipulate the image coming in , before uploading it to my bucket . Here 's what I have : The problem is that the uuid will always be different for the small and the original versions . How can I make const fileName = uuid.v4 ( ) passed down to each callback , so that... | const singleImageUploadJpg = multer ( { storage : multerS3 ( { s3 : s3 , bucket : `` muh-bucket '' , acl : `` public-read '' , key : function ( req , file , cb ) { const fileName = uuid.v4 ( ) ; cb ( null , fileName ) ; } , shouldTransform : function ( req , file , cb ) { cb ( null , true ) ; } , transforms : [ { id : ... | How to pass a unique uuid to each callback ? |
JS | I am making small utility to compile javascript block using C # . I am trying to understand ternary operator 's execution flow . Now when I am running a javascript using Chrome or Firefox : It should have give me result `` T '' or `` F '' if `` o+=2 '' returns false . But instead of those it returns `` 78F '' . Can any... | var k = 27 ; var o = 78 ; var a = k < 100 ? o+=2 > 11 ? `` T '' : `` F '' : o < 100 ? `` J '' : `` P '' ; alert ( a ) ; | Javascript ternary operator result |
JS | Are the following code snippets equivalent ? Version 1Version 2 | function doSomething ( ) { var defer = $ q.defer ( ) ; foo ( ) .then ( function ( ) { bar ( ) .then ( function ( ) { defer.resolve ( ) ; } ) ; } ) ; return defer.promise ; } function doSomething ( ) { return foo ( ) .then ( bar ) ; } | Simplifying promises in Javascript |
JS | I 've been working on a project for a client and had a lot of fun integrating SignalR into the system.Everything seems to work really well and the client is really excited about how the SignalR gives true real-time feedback for their application.For the most part everything has gone swimmingly , however I 've come into... | public class ClientHub : Hub { [ ... ] protected void UpdateRecords ( List < Int32 > ChangedValues ) { using ( var database = new DbContext ( ) ) { foreach ( Record R in database.Records.Where ( Rc = > ChangedValues.Contains ( Rc.Id ) ) { SignalRFormattedRecord Serialized = new SignalRFormattedRecord ( Record ) ; forea... | SignalR client calls fail for certain languages |
JS | I have a list like so : And I need to add the class active to each item individually and remove it on the previous item on click.Something similar to this question Vanilla JS remove class from previous selection however I need to use For loop instead of ForEach due to old browser compatibility.I 've been trying to adap... | < ul > < li class= '' item '' > Item 1 < /li > < li class= '' item '' > Item 2 < /li > < li class= '' item '' > Item 3 < /li > < /ul > const items = document.querySelectorAll ( `` .item '' ) ; for ( let i = 0 ; i < items.length ; i++ ) { const item = items [ i ] ; item.addEventListener ( `` click '' , addActiveClass ) ... | Add a class to one and only one element from an HTML list on click |
JS | I am gon na try to explain my problem properly . I want to generate number every 30 seconds , like this : This works good , but not same on each device , like if I open the page with this code , I will get random number , but if my friend opens it after e.g . 5 seconds since I have opened the page , there arises delay ... | function getRandomNumber ( min , max ) { return Math.floor ( Math.random ( ) * ( max - min + 1 ) ) + min ; } setTimeout ( function ( ) { getRandomNumber ( 0,14 ) ; } , 30000 ) ; | How can I call function every 30 seconds on every devices in the same time ? |
JS | Note : This is only for learning purpose..I have the above piece of javascript code written . When I load the page it shows an alert box saying 'Testing'.So I am guessing getElementById is a method of the document object and I 've overwritten it to alert ( 'testing ' ) , which is why its showing me the alert box when t... | console.log ( this ) ; document.getElementById = function ( ) { alert ( 'testing ' ) ; } document.getElementById ( 'someID ' ) ; | Where is the method document.getElementById defined ? |
JS | I have a function which takes a callback function . How can I set the 'this ' variable of the callback function ? eg . | function ( fn ) { //do some stuff fn ( ) ; //call fn , but the 'this ' var is set to window // , how do I set it to something else } | Javascript - how do i set the 'this ' variable for a function |
JS | I guess I will start out with a link to a jsfiddle of my projectI am going to explain how it should work and my main problem.Basically it has three `` lines '' depicted at the top by a selector box . Each line has a varying amount of `` parts '' which show up on the left sidebar . When a part is selected , a form slide... | $ ( 'ul # parts ' ) .find ( 'button ' ) .on ( 'click ' , function ( ) { ADDUPDATETOGGLE = `` ADD '' ; CSPC = $ ( this ) .attr ( `` data-part '' ) ; showForm ( ) ; } ) ; $ ( 'select.lineChoice ' ) .on ( 'click ' , function ( ) { currentLine = updatePartList ( currentLine ) ; updateJobList ( jobListByLine [ currentLine ]... | A `` .on ( ) '' action listener seems to stop working |
JS | If I have a function like this : and then assign a static property like this : But say I want to override the function with another function like this : Since I assigned a new function to a , it ’ s static properties are lost . Is there a neat way to keep the static properties without looping and manually copying them ... | function a ( ) { console.log ( ' a ' ) ; } a.static = 'foo ' ; var old = a ; a = function ( ) { console.log ( 'new ' ) ; old.call ( this ) ; } ; a.static // undefined $ .fn.modal = function ( ) { // some code } ; $ .fn.modal.defaults = { // some object } ; var old = $ .fn.modal ; $ .fn.modal = function ( ) { // do my t... | Overriding a function without removing static properties |
JS | I have this code on CodePen : https : //codepen.io/anon/pen/OdOyJXthat works perfectly , and I am confused about why this works.In the JavaScript settings , there is no preprocessor selected , so I expect the JSX syntax to fail as `` < `` is an invalid token.What makes this work on CodePen ? | ReactDOM.render ( < div > Hello , world ! < /div > , document.getElementById ( 'root ' ) ) ; | How does this React code work on CodePen even if no preprocessor is selected ? |
JS | I 'm sorry the question title is so vague , but I was looking at some code from a Job posting boards conversion tracking software and ran across this for the first time.Why are they breaking up the string literal in this manner ? Specifically ' < /ifr'+'ame > ' | document.write ( ' < i ' + 'mg height= '' 1 '' ' + 'width= '' 1 '' border= '' 0 '' ' + 'src= '' ' + url + ' & ifr ' + 'ame=0 '' / > ' ) ; document.write ( ' < /ifr ' + 'ame > ' ) ; | Javascript - breaking up string literals ... why ? |
JS | I have a local JSON file that contains `` Course Categories '' and `` Titles '' . Each Category has many Titles and each Title corresponds with one Category.I 've created three separate divs : `` Top Courses '' , `` Newly-Added Courses '' , and finally `` Top Courses '' , and the divs are populated by Categories . Clic... | var testjson = { `` d '' : { `` results '' : [ { `` Title '' : `` Aardvark '' , `` Category '' : `` Animals '' , `` Description '' : `` a-desc '' , `` TopTrainingCourse '' : false , `` ID '' : 1 , `` Modified '' : `` 2019-03-05T20:13:46Z '' , `` Created '' : `` 2019-03-05T20:13:36Z '' } , { `` Title '' : `` Red Panda '... | Appending elements to div depending on JSON data |
JS | I have this function : function Foo ( ) { } According to this picture : So if I write : Foo.prototype.constructor Now - it references to the constructor function which created the Foo { } object which is function Foo ( ) { } All ok.So where is the question ? Foo.prototype is an object instance -- > Foo { } And who is t... | > > Foo.prototype - > Foo { } __proto__ is the ctor 's prototype _________________________________________________________________________________________ Foo.prototype.__proto__ is the function Foo ( ) { } Foo.prototype | Javascript __proto__ - clarification ? |
JS | I 've been working with scripts making use of setInterval ( fn , delay ) function in my application and after reading about how setTimeout and JS work I encounter some weird results so I made a test : Here is the jsfiddle https : //jsfiddle.net/jyq46uu1/2/And the code as suggested : Ok , from what I 've red from http :... | var limit = 1000000000 ; var intervals = 0 ; var totalTime = new Date ( ) ; var startTime = new Date ( ) ; var uid = setInterval ( function ( ) { // final lap ? if ( intervals == 9 ) clearInterval ( uid ) ; for ( i = 0 ; i < limit ; i += 1 ) { // just working the CPU } // reduce the iterations limit = limit / 10 ; inte... | Javascript setTimeout unexpected output |
JS | I want to know if it is possible to hit an event if the period sign . is removed from textbox.for example I have a textbox # Quantity which takes numeric values as input with period signand i have a drop down control # unitValue which have three optionI had successfully hit an event on period sign . key press as follow... | $ ( `` # Quantity '' ) .keypress ( function ( e ) { if ( e.which == 46 ) { //successfully disabled Gram in Unit } } ) ; | how to check if period sign ( . ) is removed from the word in textbox in jQuery ? |
JS | Let 's say that I have a functionA defined like this : I can then call it and pass an object to work on as functionA ( someObject , someParams ) .I can , however , transform this example with apply ( ) : Both approaches seems to be achieving the same goal , or am I missing something ? But since apply ( ) does exist in ... | functionA = function ( myObject , someParams ) { myObject.save_some_data = someParams ; myObject.processed = true ; } functionA = function ( someParams ) { this.save_some_data = someParams ; this.processed = true ; } functionA.apply ( someObject , [ someParams ] ) ; | Which approach is better : function.apply ( < this > , args ) or having a function to accept < this > as argument ? |
JS | I get this data as an ajax response : This is just a portion of the Data , but it continues in the same format.I do n't have access to the source of the files that generate this data.Is this a known format or something custom ? | { `` idArray '' = ( `` 99516 '' , `` 99518 '' , `` 97344 '' , `` 97345 '' , `` 98425 '' ) ; `` frame '' = { `` size '' = { `` width '' = `` 8 '' ; `` height '' = `` 8 '' ; } ; `` origin '' = { `` x '' = `` 244 '' ; `` y '' = `` 345 '' ; } ; } ; } , | what is the format of this data ? is it a custom format ? |
JS | I 'm trying to have form input elements , which are uncontrolled because of our use of jQuery UI DatePicker and jQuery maskMoney , render errors underneath them as soon as user types something invalid for that field , as well as disable the button on any of the errors . For some reason , none of that is working right.M... | class MainComponent extends React.Component { constructor ( props ) { super ( props ) this.state = { payrates : [ new PayRate ( new Date ( 2019 , 2 , 1 ) , 0.00 ) , ] , errors : { rate : `` , date : `` } , currentPayRate : new PayRate ( ) // has Rate and EffectiveDate fields } // binding done here this.appendValue = th... | React stale error date on child components |
JS | Good evening , I 'm using a material-ui Card inside a React functional component , with a CardMedia such as : I 'm trying to determine the image file size in bytes . After some research I found solutions which use XMLHttpRequest . It seems strange to me to download the file again.I found how to get the image width and ... | < CardMedia className= { classes.media } image= { props.image } title= { props.cardTitle } / > function checkImage ( ) { var img = new Image ( ) ; img.addEventListener ( `` load '' , function ( ) { console.log ( this.naturalWidth + ' '+ this.naturalHeight ) ; } ) ; img.src = props.image ; } | determining image file size of a react Material-ui CardMedia |
JS | I am using D3 to render a vector map , based off of a GeoJSON dataset.I have an existing path and I need to transform the path using a tween . To do this I need to use D3 to lookup the current projection object for this path . However , I ca n't seem to figure out the syntax to achieve this . Is it possible to look up ... | const mapPath = d3.select ( 'path.states ' ) ; | How can I find the projection of an existing D3 path |
JS | I want to programmatically add a gradient background to an element . With proper CSS that would be something like thisNow , I want to do it with JavaScript . So I thought up of something like this : However , that wo n't work . The background property will be overridden each time , and only the last gradient on the lis... | background : -moz-linear-gradient ( top , # 000000 0 % , # ffffff 100 % ) ; /* FF3.6+ */background : -webkit-gradient ( linear , left top , left bottom , color-stop ( 0 % , # 000000 ) , color-stop ( 100 % , # ffffff ) ) ; /* Chrome , Safari4+ */background : -webkit-linear-gradient ( top , # 000000 0 % , # ffffff 100 % ... | How to add vendor prefixed gradients to an element with vanilla JavaScript ? |
JS | I have a stream of numbers which increase by a constant amount which I want to sub-sample . Given a constant sample interval , I want to buffer the stream until the difference between the first and last buffered value are greater or equal to interval . It would then emit this array , so similar to the buffer operator.I... | const interval = 15 ; //example stream would be : 5 , 10 , 15 , 20 , 25 , 30..Observable.pipe ( bufferUntil ( bufferedArray = > { let last = bufferedArray.length - 1 ; return ( bufferedArray [ last ] - bufferedArray [ 0 ] > = interval ) ; } ) ) .subscribe ( x = > console.log ( x ) ) ; //With an expected output of [ 5 ,... | rxjs - buffer stream until function returns true |
JS | I 've got an array of functions and looking for a concise way to call each one in order.this works : and so does this : however this raises a TypeError : Why does n't the latter example work ? | fns = [ function a ( ) { console.log ( ' a ' ) } , function b ( ) { console.log ( ' b ' ) } , function c ( ) { console.log ( ' c ' ) } , ] fns.map ( function ( f ) { f ( ) } ) fns.map ( function ( f ) { Function.call.call ( f ) } ) fns.map ( Function.call.call ) | Call each function in the list |
JS | also there is so the problem is when I scroll this scrollview over the html img it gets the touch and the phone vibrates . Is there any way to disable webview hapticfeedback either from source end ( html ) or from react-native-webview end ? I think this is because while scrolling the img tag takes the interaction as lo... | < ScrollView ref= { scrollRef } horizontal scrollEnabled= { isScroll } contentContainerStyle= { { height : HEIGHT , overflow : 'hidden ' } } style= { { width : metrics.screenWidth - widthOffset , } } onScroll= { _onScroll } > < WebView ref= { webviewRef } automaticallyAdjustContentInsets= { false } scrollEnabled= { fal... | Is there any way to disable hapticFeedback in react-native-webview |
JS | It 's so hard to search for symbols in Google , so I ask here instead. < ! -- looks like a comment for me , but it does n't work like html . Or it 's a one line comment just like // ? What is the purpose and benefit of using this ? Thankssample code : | < script type= '' text/javascript '' > < ! -- alert ( `` example '' ) ; // -- > < /script > | what does < ! -- in Javascript do ? |
JS | What happens to JavaScript literals ( strings , numbers ) that are not bound ( aka assigned ) to a variable ? The browser appears to ignore them , but I could n't find a specific rule in the spec | // A comment '' Practically , also a comment '' var assigned = `` something '' 53423.0022 NaN '' does it impact performance '' // or is it treated just like a comment ? | What happens to unbound JavaScript literals ? |
JS | So , my team is using the HTML5 Boilerplate and has the site nearly finished . I want to do a quick JavaScript test to make sure the client can add their own JavaScript if they so desire . I know the type attribute for the script tag is not required when using the HTML5 doctype , but the JavaScript alert does n't even ... | < script > alert ( `` HELP '' ) ; < /script > < script type= '' text/javascript '' > alert ( `` HELP '' ) ; < /script > | Curious about peculiar JavaScript issue regarding script tag type attribute |
JS | Using the Web MIDI API , I can send some messages : I can also schedule some messages to be well-timed and sent in the future : Now , suppose I 've scheduled many messages to be sent in the future over several seconds , and now I want to cancel the sending of those messages . According to the spec , I should be able to... | // Note onoutput.send ( [ 0x90 , 0x20 , 0x50 ] ) ; // Note off , 1 second lateroutput.send ( [ 0x80 , 0x20 , 0x40 ] , performance.now ( ) + 1000 ) ; output.clear ( ) ; | Clearing MIDI output buffer |
JS | I have multiple conditions to be checked and executed like below.I think using switch statement does n't make sense here since we are not evaluating case statement expression against switch expression.So is it okay to go with multiple if else statements or any better alternative approach ? | if ( date == current_date & & source === `` s3 '' ) { table_name = `` Table1 '' ; } else if ( date == current_date & & source ! == `` s3 '' ) { table_name = `` Table2 '' ; } else if ( date ! == current_date & & source === `` s3 '' ) { table_name = `` Table3 '' ; } else if ( date ! == current_date & & source ! == `` s3 ... | alternative approaches to multiple if else conditions |
JS | Recently I ran into some interesting behaviour related to event-bubbling . I have created a code-pen to illustrate this : https : //codepen.io/anon/pen/XGmxXrAll I am doing there is bind two event-listeners ( or I guess three including the one that removes the button ) . One on the document and one on the document.body... | $ ( document ) .on ( `` click '' , `` button '' , ( ) = > console.log ( `` document knows '' ) ) ; $ ( document.body ) .on ( `` click '' , `` button '' , ( ) = > console.log ( `` document body knows '' ) ) ; $ ( `` button '' ) .on ( `` click '' , e = > $ ( `` button '' ) .remove ( ) ) ; < script src= '' https : //cdnjs... | How can an event bubble to document but not to document.body ? |
JS | I try to implement example from book React & Redux page 204 , but , there is strange issue - There is TypeError ( 0 , _ColorReducer.color ) is not a function error in React codeI have 2 reducers for one color and for array of colors : and So , problem in colorsReducer in line whereThe full code example is here Can you ... | import React from `` react '' ; import * as C from `` ./Constants '' ; import { color } from `` ./ColorReducer '' ; export const colorsReducer = ( state = [ ] , action ) = > { switch ( action.type ) { case C.ADD_COLOR : return [ ... state , color ( { } , action ) ] ; case C.RATE_COLOR : return state.map ( item = > colo... | There is TypeError ( 0 , _ColorReducer.color ) is not a function error in React + Redux code |
JS | I need help with my CSS and javascript code which I have uploaded to codepen.I am trying to use CSS motion path , I would like to be able to control this with JavaScript , so when you press the `` Forward button '' it runs to the last keyframe and that works , But when I press the `` Back button '' then nothing happens... | function myForwardFunction ( ) { document.getElementById ( `` pathed '' ) .style.animationPlayState = `` running '' ; } function myBackFunction ( ) { document.getElementById ( `` pathed '' ) .style.animationDirection = `` reverse '' ; } section { width : 244px ; height : 200px ; border : 2px dashed lightgrey ; } body {... | CSS motion path onClick |
JS | I would like to send a ~10MB json data in a textarea named `` data '' . If the data is 1-2KB , then it works perfectly . But with a large json , the $ _POST [ 'data ' ] is empty for some reason.I ca n't upload the json otherwise , because it is generated clientside , it 's not a file.I 've tried this code , but still n... | form.setAttribute ( 'enctype ' , 'multipart/form-data ' ) ; memory_limit = 256Mupload_max_filesize = 64Mpost_max_size = 64M | $ _POST [ 'data ' ] is not defined , if data is too large |
JS | I 'm making either 1 or more REST/ajax calls to validate some user information . The rest calls are working well and the information is coming back . The issue I 'm facing is n't with that part of the code , which looks something like this.If there is more than one user in the initial array , then the arguments in my .... | function ensureUsers ( recipients ) { var promises = [ ] ; for ( var key in recipients ) { var payload = { 'property ' : recipients [ key ] } ; promises.push ( $ .ajax ( { ... } ) ) ; } return $ .when.apply ( $ , promises ) ; } ... .ensureUsers ( users ) // users is an array of 1 or more users .done ( function ( ) { co... | Working with 1 or more jQuery promises |
JS | I know this question might be silly just would like to know , and I am not sure whether the topic matches to my current asking . But still thought to ask it.I see the first one `` function '' is not triggered on page load or refresh but where as second one fire ( ) gets triggered when page loaded , and later this funct... | < button id= '' Clk '' > Click on me < /button > document.getElementById ( `` Clk '' ) .onclick = function ( ) { alert ( `` firedme ! '' ) } document.getElementById ( `` Clk '' ) .onclick = fire ( ) ; function fire ( ) { alert ( `` I am fired ! '' ) } | Differences between javascript function |
JS | Hi please help me to validate the user id with email id and the password should contain uppercase lowercase and atleast one character ? | < ! DOCTYPE html > < html > < head > < title > Login Page < /title > < meta charset= '' utf-8 '' > < meta name= '' viewport '' content= '' width=device-width , initial-scale=1 '' > < link rel= '' stylesheet '' href= '' http : //maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css '' > < script src= '' https : ... | how to validate email id and password and password should contain lowercase , uppercase and minimum one character and both fields should be inline ? |
JS | I have the following array and I am looking to retrieve the index of the original ( sorted ) array where the element is changing and how often that individual element exists.The desired outcome should be like this : Thank you very much for any suggestion.Cheers . | ab = [ 1,1,1,3,3,5,5,5,5,5,6,6 ] ac = [ 0,3,5,10 ] ad = [ 3,2,5,2 ] | How can I get index of sorted list where element changes ? |
JS | I have a set of named requirejs modules with constructor-as-a-function.I want to be able to attach modules to HTML in corect order NOT USING requirejs API via script tagsattach and use modules USING requirejs APINow , then I attaching a script with define call to a document , script is successfully loaded , but module ... | define ( 'myModule ' , [ 'import1 ' , 'import2 ' ] , function ( i1 , i2 ) { ... } ) ; | requirejs - construct a module when it is defined , not when it is required |
JS | I have form inputs that are generated based off an XML file . We keep a reference of nested elements in the XML file via data-* attributes which can later be used to build an object . For example : Becomes < input type= '' text '' data-nest= '' parent.child.grandchild1 '' value= '' first '' / > < input type= '' text ''... | < parent > < child > < grandchild1 > first < /grandchild1 > < grandchild2 > second < /grandchild2 > < /child > < /parent > parent : { child : { grandchild1 : first , grandchild2 : second } } < child > < grandchild > first < /grandchild > < grandchildFriend > firstFriend < /grandchildFriend > < /child > < child > < gran... | Create array of objects based off the same property names |
JS | I have a library , written in Typescript , that is being distributed in 2 files : a compiled ECMAScript-2015 compatible Javascript file index.js and a Typescript declaration file index.d.ts . My goal is to make library accessible for both Javascript and Typescript developers ( so that they have proper typings and autoc... | // index.tsclass MyClass { private field1 : string = `` foo '' ; private field2 : string = `` bar '' ; constructor ( ) { console.log ( this.field1 , this.field2 ) ; } } // generated index.d.tsdeclare class MyClass { private field1 ; private field2 ; constructor ( ) ; } // index.tsclass MyClass { # field1 : string = `` ... | Typescript generates declaration d.ts file with ` # private ; ` field |
JS | Recently I needed to use RxJS . I tried to design an error handling flow , but I discovered some weird syntax passing method arguments : Link to minimal reproduction : https : //stackblitz.com/edit/rxjs-6-5-error-handle-no-arrow-issueSteps to reproduce : Use RxJS 6.5Create a function return observableSubscribe to obser... | .subscribe ( x = > { } , console.warn // < - Why does this compile , and warn 'is not 7 ' in debug console ? ) ; import { throwError , concat , of } from `` rxjs '' ; import { map } from `` rxjs/operators '' ; const result = concat ( of ( 7 ) , of ( 8 ) ) ; getData ( result ) .subscribe ( x = > { console.log ( `` typeo... | Why does RxJS subscribe allow omitting the arrow function and the following method argument ? |
JS | I 'm using Pikaday.js like so : I know that the answer lies in this example from the documentation : But I ca n't figure out how to use full day ( Monday , Tuesday , Wednesday , etc ) and full month names ( January , February , etc ) instead of the abbreviations ( Mon , Tue , Wed ... Jan , Feb , Mar ... etc ) I do n't ... | new Pikaday ( { field : document.getElementById ( 'top-banner-datepicker ' ) , minDate : new Date ( ) var picker = new Pikaday ( { field : document.getElementById ( 'datepicker ' ) , format : 'D/M/YYYY ' , toString ( date , format ) { // you should do formatting based on the passed format , // but we will just return '... | Pikaday JS How to use full day and month names for input format without moment js |
JS | In an effort to stop writing a lot of duplicate code I 'm trying to not open then calls . I 'd preferably only like to pass functions around from a top level . Like this.However the above code does n't work . The test below shows that you cant pass a bound promisifyAll async function . The reason is that the then value... | function ensureLink ( srcPath , dstPath ) { dstPath = fsRedux.predictDir ( srcPath , dstPath ) var dstDir = path.dirname ( dstPath ) return fsRedux.exists ( dstPath ) .then ( _.partialRight ( fsRedux.ifFalseThrow , false , new Error ( dstPath+ '' exists can not ensure link '' ) ) ) .then ( _.bind ( fsExtra.mkdirsAsync ... | Writing promises without opening then calls |
JS | See my example code belowWhen both variable a and b are in global scope , why I am getting error message for b . But there is no error message for variable a ? what is the reason ? can anyone please explain me ? | < script > alert ( a ) ; // undefinedalert ( b ) ; // It is Error , b is not defined.var a=1 ; b=10 ; < /script > | when I use global scope variable without 'var ' , its showing me Error . why ? |
JS | I 've noticed residual pixel fragments left behind after a simple CSS animation of size and box shadows from one side of the screen to the other.Here is the Code Pen so you can see it in action , and it looks like this in Chrome 66 : Is there anyway to remove these leftover fragments ? Here is the code : | * { margin : 0 ; padding : 0 ; box-sizing : content-box ; } # container { display : flex ; align-items : center ; height : 100vh ; } # box { position : relative ; width : 150px ; height : 150px ; animation : move 2s infinite alternate ease-in-out ; } @ keyframes move { 0 % { left : 0 ; background-color : blue ; border-... | CSS Animation Residual Pixel Fragments |
JS | Bit of a mouthful that one ... I 'm currently using the script below to generate a random number between 1 and 200 in cells I6 : M6 . For my intended purpose this script has two problems ( neither of which are major but I would like some `` polish '' .Problem 1 ) not-mutually exclusive . This is the biggest issue as ea... | ///////////////////////////////////////function onOpen ( ) { var sheet = SpreadsheetApp.getActiveSpreadsheet ( ) ; var entries = [ { name : '' Roll Dice '' , functionName : '' rollDice '' } ] ; sheet.addMenu ( `` Script '' , entries ) ; } ; function rollDice ( ) { var ss = SpreadsheetApp.getActiveSpreadsheet ( ) ; var ... | Google sheets mutually exclusive numerical order random number generator |
JS | I currently have two Knockout extension functions . One adds a member to the Observable while the other intercepts the read and write operations . When combining the extension methods the order of application has an unwanted effect.Simplified code examples below.In the numeric method I can check for the formatted membe... | ko.extenders.format = function ( target ) { var result = ko.computed ( function ( ) { return `` $ '' + target ( ) ; } ) ; target.formatted = result ; return target ; } ; ko.extenders.numeric = function ( target , precision ) { var result = ko.computed ( { read : function ( ) { var current = parseFloat ( target ( ) ) ; ... | What is a good pattern to preserve custom properties created in a Knockout extension ? |
JS | I 'm watching this lecture : http : //www.youtube.com/watch ? v=Kq4FpMe6cRsAt minute 35 , the above shown issue is presented . The lecturer states that some browsers will return foo instead of 8 . Why ? Btw , while writing this question , I figured it out , but I 'll post this question anyway because it 's an interesti... | // the speaker states that `` 'bar ' is just some function // that invokes whatever function is passed to it '' function bar ( fn ) { fn ( ) ; } function foo ( ) { var x = 8 ; bar ( function baz ( ) { return x ; } ) ; } Object.prototype.x = 'foo ' ; | EcmaScript 5 Google TechTalk - Scoping accident 1 example |
JS | I need to change the font-size in a div when someone selects a different font size.Here is my code which I know is working because I added an alert to it . The only thing not working is it changing the font size.CSS : JAVASCRIPT : HTML : I just ca n't figure out what is wrong . | .heading { font-size:18px ; } $ ( ' # htsize ' ) .on ( 'change ' , function ( e ) { var optionSelected = $ ( `` option : selected '' , this ) ; var valueSelected = this.value ; $ ( `` .heading '' ) .css ( `` font-size '' , valueSelected ) ; } ) ; < SELECT id= '' htsize '' name= '' htsize '' style= '' width:100px ; font... | Change font-size When Selection is made |
JS | Is there any way to add a button for prism in summernote editor ? I have prism css and js file included in my view but i do n't know how to add button for it in editor : Any idea ? | $ ( document ) .ready ( function ( ) { $ ( '.summernote ' ) .summernote ( { minHeight : 200 , toolbar : [ [ 'style ' , [ 'style ' , 'bold ' , 'italic ' , 'underline ' , 'clear ' ] ] , [ 'font ' , [ 'strikethrough ' , 'superscript ' , 'subscript ' ] ] , [ 'fontsize ' , [ 'fontsize ' , 'fontname ' , 'fontsizeunit ' , 'he... | Add prism to summernote |
JS | Why does the following code alert 2 ? What I can see is that somehow the y function is getting executed and x function is ignored . ( I have made sure that I put alert in both functions , and only the alert in y is called which make me believe that the x function is not being called at all ) And if I remove the y funct... | var f = ( function x ( ) { return 1 ; } , function y ( ) { return 2 ; } ) ( ) ; alert ( f ) ; | Why is the result of two function definitions joined by a comma ? |
JS | Curious bit of code here ... Here 's the jsFiddleIs function x ( ) { } called at all after return ? Why not alert 10 ? | var x = 5 ; function fn ( ) { x = 10 ; return ; function x ( ) { } } fn ( ) ; alert ( x ) ; | Why does this alert 5 ? |
JS | I 've noticed that babel transpiledintoWhy did babel use the comma operator with 0 as first expression in the invocation of the install function ? | import { install } from 'source-map-support ' ; install ( ) ; var _sourceMapSupport = require ( 'source-map-support ' ) ; ( 0 , _sourceMapSupport.install ) ( ) ; | Why does babel wrap _sourceMapSupport.install ( ) with ( 0 , ... ) ( ) ? |
JS | I often see in third party JavaScript code that after : object is often nulled and comment along this operation says that it is done for IE : What 's the real purpose ? Any resource on that ? | var el = document.getElementById ( elementId ) ; el = null ; // IE | Why object has to be nulled for IE after it was document.getElementById-ed ? |
JS | I have this piece of code : Right now ._name is not `` private '' . I want to make ._name `` private '' , but at the same time i do not wish to create additional functions for each instance of Human ( in other words tom.Shout Must be === to john.Shout ) because creating additional functions for each instance is just we... | var Human=function ( name ) { this._name=name ; } ; Human.prototype.Shout=function ( ) { alert ( this._name ) ; } ; var tom=new Human ( `` tom '' ) ; var john=new Human ( `` john '' ) ; alert ( tom.Shout===john.Shout ) ; | Is there anyway to have instances share the same function yet at the same time have private variables ? |
JS | What I am really asking is this ; if there are dependencies which are impossible to compile into the unity build , is there a way of still calling them from within the unity and simply using the scripts loaded into the browser from the website and communicating with them ? Relevant documentation does not address this d... | gameInstance = UnityLoader.instantiate ( `` gameContainer '' , `` /Build/DomumProto16_Web.json '' , { onProgress : UnityProgress } ) ; gameInstance.SendMessage ( 'Manager ' , 'Filter ' , JSON.stringify ( filterActive ) ) ; function showStudentWork ( studentIndex ) { //make sure to remove all the var x = document.getEle... | Unity - communicating with clientside Javascript and ajax . How to pass data back to the webpage from unity ? |
JS | Not sure how better to word this ( and , consequently , could n't find previous answers , though I expect this has been answered before ) , but I 'm interested in whether there 's a way to turn code like this : To something like the below ( not sure how better to express it ) : As in , is there a way to avoid the exten... | if ( this.props.mailboxFilter == 'sent ' ) { return this.currentUser.canActOnBehalfOf ( m.senderID ) ; } else { return ! this.currentUser.canActOnBehalfOf ( m.senderID ) ; } var bangOrNot = this.props.mailboxFilter == 'sent ? ' ! ' : `` ; bangOrNot ( this.currentUser.canActOnBehalfOf ( m.senderID ) ) ; | Conditionally apply a ! to a method in JavaScript |
JS | I noticed that for my site summary the Google Bot seemed to be putting up the first batch of text it found . This happened to be the noscript tag that told the user to turn JavaScript on , if it was not enabled.I thought I would thwart it , by putting a hidden div before that , that actually contained a site summary.No... | < meta name='description ' content='My Summary ' > < body > < div id='google_bot ' style='display : none ' > My Summary < /div > | How to feed a site summary to the Google Bot ? |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.