lang stringclasses 4
values | desc stringlengths 2 8.98k | code stringlengths 7 36.2k | title stringlengths 12 162 |
|---|---|---|---|
JS | I have been creating a clone of agar.io and I do n't understand why the circles start vibrating when they touch each other . Below is my code : | var canvas , ctx , width = innerWidth , height = innerHeight , mouseX = 0 , mouseY = 0 ; var camera = { x : 0 , y : 0 , update : function ( obj ) { this.x = obj.x - width / 2 ; this.y = obj.y - height / 2 ; } } , player = { defaultMass : 54 , x : 0 , y : 0 , blobs : [ ] , update : function ( ) { for ( var i = 0 ; i < t... | Why circles are vibrating on collision ( Canvas ) |
JS | Here 's an example that demonstrates the problem I am facing : I 'm aware that objects that were instantiated in another context , are considered `` foreign '' and end up being wrapped by a ScriptObjectMirror instance . I am assuming this is why I 'm running into a problem here . I believe whenever x is dereferenced , ... | ScriptEngine engine = new NashornScriptEngineFactory ( ) .getScriptEngine ( new String [ ] { `` -strict '' } ) ; try { engine.eval ( `` function Foo ( src ) { this.src = src } ; var e = { x : new Foo ( \ '' what\ '' ) } ; '' ) ; ScriptContext c = new SimpleScriptContext ( ) ; c.setBindings ( engine.createBindings ( ) ,... | === returns false in Nashorn when both references should be pointing to the same object |
JS | In my App.js I have the following path : The registration screen component is : What i want to achieve is the following : When visiting /register the RegistrationChooser component is loaded , and when visiting /register/bookLover the BookLoverRegistration component is shown and the RegistrationChooser component is hidd... | < Route path= '' /register '' component= { RegistrationScreen } / > import React , { Component } from 'react'import { Route , Switch } from 'react-router ' ; import RegistrationChooser from './RegistrationChooser ' ; import BookLoverRegistration from './BookLoverRegistration ' ; import BookLoverProRegistration from './... | React-router nesting to show different components |
JS | So this is an awkward question to ask , but I 'm learning NodeJS and I have a question . In Java when I call a method from an object , the this instance remains the same ( as in this example ) .This returns true ( in theory , that 's code off the top of my head ) . However , in NodeJS when I attempt to do something sim... | private Test inst ; public Test ( ) { inst = this ; this.myFunction ( ) ; } private void myFunction ( ) { System.out.println ( inst == this ) ; } var MyObject = function ( ) { this.other = new OtherObject ( ) ; this.other.on ( `` error '' , this.onError ) ; console.log ( this ) ; //This returns the MyObject object } My... | nodejs - Which `` this '' is this ? |
JS | The following code calls console.log prints `` hello '' : However , the code below throws TypeError : throws : Can anyone explain this weird scenario ? ( Of course it 's the same for both call and apply ) | console.log.call ( console , `` hello '' ) x = console.log.callx ( console , `` hello '' ) Uncaught TypeError : x is not a function at < anonymous > :1:1 | Function.prototype.call unexpected behavior when assigned to a variable |
JS | I currently have an array that resembles the array below : I am looking for the fastest way to get something like below where I could split/sort the array by a property in the object , in this example it would be 'color ' : I could write a function for this but I was thinking there may be something to do this already i... | [ { id:1 , color : 'red ' } , { id:2 , color : 'blue ' } , { id:3 , color : 'red ' } , { id:4 , color : 'green ' } , { id:5 , color : 'blue ' } , ] [ [ { id:1 , color : 'red ' } , { id:3 , color : 'red ' } , ] , [ { id:2 , color : 'blue ' } , { id:5 , color : 'blue ' } , ] , [ { id:4 , color : 'green ' } , ] ] | How to split an array into arrays by an objects property using javascript ? |
JS | I was reading Douglas Crawford 's piece on creating private variables in javascript classes.In it he says you have to state that = this in order to `` make the object available to private methods '' . However , I was able to build an example which has private members , private methods and public methods without definin... | function Form ( id_code ) { //private variable var id_code = id_code ; var color = ' # ccc ' ; //private method function build_style_attribute ( ) { return 'style= '' background-color : '+color+ ' '' ' ; } //public method this.render = function ( ) { return ' < div '+build_style_attribute ( ) + ' > '+id_code+ ' < /div ... | How would defining ` that = this ` help me create private variables/members ? |
JS | I am looking to combine these two arrays into a single one . I want any id information that is the same to be filtered so that it only appears once , making it a simple list of name , age , occupation , and address . I have tried simply concating the info , using splice , using filter ... but I just cant seem to get th... | var a = [ { id : 'aBcDeFgH ' , firstName : 'Juan ' , lastName : 'Doe ' , age : 32 } , { id : 'zYxWvUt ' , firstName : 'Alex ' , lastName : 'Smith ' , age : 24 } ] var b = [ { id : 'aBcDeFgH ' , occupation : 'architect ' , address : { street : '123 Main St ' , city : 'CityTown ' , Country : 'USA ' } } , { id : 'zYxWvUt ... | Concating two arrays into one |
JS | I have a problem to use $ formatters.My goal is to hide phone number , just leave the last 4 chars visible.It 's ok if you do n't write anything in the input . If you write something , the model is affected by the mask and I register the hidden phone in DB ... Here 's the directive I use : And for your facility , here ... | .directive ( 'tsHideField ' , function ( ) { return { require : 'ngModel ' , restrict : ' A ' , link : function ( scope , element , attributes , controller ) { var maskValue = function ( value ) { if ( ! value ) { return `` '' ; } if ( value.length < = 4 ) { return value ; } var valueHide = `` '' ; if ( value.indexOf (... | directive $ formatters affect ngModel when writing |
JS | I have the following array of objects : I want to define a function , lookUpProfile ( firstName , prop ) , which for the input data : will return : This is my solution so far which does n't return something till now : Has anyone any idea to solve this ? Thanks | var contacts = [ { `` firstName '' : `` Akira '' , `` lastName '' : `` Laine '' , `` number '' : `` 0543236543 '' , `` likes '' : [ `` Pizza '' , `` Coding '' , `` Brownie Points '' ] } , { `` firstName '' : `` Harry '' , `` lastName '' : `` Potter '' , `` number '' : `` 0994372684 '' , `` likes '' : [ `` Hogwarts '' ,... | Return object 's property if it is found into an array of objects in JavaScript |
JS | I 'm trying to create a valid test case for the promiseRateLimit function below . The way the promiseRateLimit function works is it uses a queue to store incoming promises and will place a delay between them . Here 's an example of the function in action.The example promise takes 50ms to run and the promiseRateLimit fu... | import Promise from 'bluebird'export default function promiseRateLimit ( fn , delay , count ) { let working = 0 let queue = [ ] function work ( ) { if ( ( queue.length === 0 ) || ( working === count ) ) return working++ Promise.delay ( delay ) .tap ( ( ) = > working -- ) .then ( work ) let { self , args , resolve } = q... | Issue creating valid test case for promise rate limit function |
JS | I am porting over some Java code to JavaScript . I have a lot of member elements that are a char . Is it more efficient to make those a number or a string ( where the string will always be a single character ) ? Update : The way it 's presently used in Java is I have : And then I have lots of places where I either assi... | /** alignment is left . */public static final char TAB_STOP_LEFT = ' l ' ; /** alignment is center . */public static final char TAB_STOP_CENTER = ' c ' ; /** alignment is right . */public static final char TAB_STOP_RIGHT = ' r ' ; private char tabStop ; | What 's the best replacement for a char ? |
JS | Look at the code of below , as you can see there is a close icon floated to the right of a span element.I want the : after to behave like a button . As you could see , it makes the cursor a pointer on hover . How can I make it to behave like a button ? For example , how can I add an onclick function to it ? | span { width : 100 % ; display : inline-block ; } span : after { content : `` \2715 '' ; float : right ; position : absolute ; } span : hover : after { cursor : pointer ; } < span > Content < /span > | CSS : Is it possible to make the : :after selector behave like a button ? |
JS | I 'm trying to test whether or not an unordered string has ' 3 ' in it 5 times.For example : What regex would make the second line return true ? If regex is not the best way to test this , what is ? Thanks ! | var re = /3 { 5 } / ; re.test ( `` 333334 '' ) ; //returns true as expectedre.test ( `` 334333 '' ) ; //returns false since there is no chain of 5 3s | Javascript regex - specific number of characters in unordered string |
JS | Why does javascript evaluate the following as true , given that object foo has a valid property bar ? Based on operator precedence , I would think foo [ [ [ [ `` bar '' ] ] ] ] is trying to access a property with the array [ [ [ `` bar '' ] ] ] as the key , but why does that still `` flatten down '' to the same as foo ... | foo [ [ [ [ `` bar '' ] ] ] ] === foo [ `` bar '' ] > test = [ [ [ `` bar '' ] ] ] [ Array [ 1 ] ] > foo [ `` bar '' ] = 5 5 > foo [ test ] 5 | How does object [ [ [ `` key '' ] ] ] evaluate to object [ `` key '' ] in javascript ? |
JS | I 've inherited some JS ( that I ca n't change ) that fires a bunch of events : And I want to observe for ALL of these events , and parse out the value for section , and do something different depending on it 's contents.If it did n't change I could do this : But how do I observe an event if I only know the first part ... | jQuery ( document ) .trigger ( 'section : ' + section ) ; // where `` section '' changes dynamically jQuery ( document ) .on ( 'section : top ' , doStuff ) ; | Observe a JS event , when you only know PART of the event name ? |
JS | I have tried window.history.pushState ( `` , `` , site_url + `` + ActivityUrl ) ; and also window.history.replaceState ( `` , `` , site_url + `` + ActivityUrl ) ; I need to update the URL in the browser without redirecting to it . All the solutions I had got are the above two , but this is not working and also not disp... | $ scope.updateUrl = function ( ActivityUrl ) { window.history.pushState ( `` , `` , site_url + `` + ActivityUrl ) ; } | Updating URL without redirection is not working |
JS | I want to filter data in an acordeon which is has 4 parts . My code 's sample is below ( I have cleared acordeon codes and some different parts in my code ) SubCategory , Lesson and SubLesson datas are come from another service and they are saving in different arrays . I want to filter datas in this view include all da... | < input type= '' text '' ng-model= '' searchText '' placeholder= '' Filter '' > < dl > < dt ng-repeat-start= '' mainCategory in mainCategories | filter : searchText '' > { { mainCategory.Name } } < /dt > < dd ng-repeat-end= '' '' > < dl > < dt ng-repeat-start= '' subCategory in subCategories [ mainCategory.ID ] | filte... | Filtering multiple arrays in multiple definition lists with AngularJS |
JS | How to have output : My below code is undefined , I want the array city + date to be together in the birthday.My code was not , check my code below : Is that any suggestion to fix this logic ? I just want to use the loop , for this . | ID : 0001Name : MikeBirthday : London 21/05/1989Hobby : Reading var input = [ [ `` 0001 '' , `` Mike '' , `` London '' , `` 21/05/1989 '' , `` Reading '' ] , [ `` 0002 '' , `` Sara '' , `` Manchester '' , `` 10/10/1992 '' , `` Swimming '' ] , [ `` 0003 '' , `` John '' , `` Kansas '' , `` 25/12/1965 '' , `` Cooking '' ]... | access array number 2 and 3 to be in one string array |
JS | Version 2.3.6Steps to reproduce : click 'select-all ' , selection is all right . next click 'set zoom as 1.5 ' , then click 'select-all ' , Result : Selection border is incorrect now.Expected Behavior : Selection works fine ( like zoom is 1 ) when the zoom is 1.5.Actual Behavior : Selection is incorrect when the zoom i... | $ ( document ) .ready ( function ( ) { var canvas = new fabric.Canvas ( 'canvas ' ) ; canvas.add ( new fabric.Rect ( { left : 50 , top : 50 , width : 75 , height : 50 , fill : 'green ' , stroke : 'black ' , strokeWidth : 3 , padding : 10 } ) ) ; canvas.add ( new fabric.Circle ( { left : 120 , top : 120 , radius : 30 , ... | selection border is incorrect while canvas 's zoom value is not 1 |
JS | I just discovered a bug in a 3rd party wordpress plugin that looks to have been caused by a javascript code minifier.The original code , I believe , was supposed to be this : Instead it had been minified to : This results in the following error in Chrome : And a similar error in Firefox . Annoyingly , in Chrome my own ... | this.id = `` ui-id- '' + ++n ; this.id= '' ui-id- '' +++n ; Uncaught ReferenceError : Invalid left-hand side expression in postfix operation var n = 1 ; var foo = 10 ; var bar = `` ID- '' ; console.log ( foo+++n ) ; // results in 11console.log ( foo ) ; // also results in 11console.log ( bar+++n ) ; // results in NaN s... | Why does javascript produce different errors for strings and literals with ++ ? |
JS | I am creating a Web app that should be completely operated through the keyboard . I must provide the user the accesskey combination for different buttons , but the way accessing them is different for each browser and platform . E.g . For Chrome or Firefox in Ubuntu , if the accesskey is `` d '' , I must press : But if ... | SHIFT+ALT+d CTRL+d | Getting the browser+platform keyboard modifiers |
JS | Given the C code below : Outputs : And this JavaScript code ( written in TypeScript , so there actually is typing involved here as well , but it is mostly inferred ) : Outputs : NOTE : Both these implementations are the same , just different languages.The C code produces the expected results and JavaScript doesn't.Ques... | int nSum = 0 ; // pNumber is 9109190866037int nDigits = strlen ( pNumber ) ; int nParity = ( nDigits-1 ) % 2 ; char cDigit [ 2 ] = `` \0 '' ; for ( int i = nDigits ; i > 0 ; i -- ) { cDigit [ 0 ] = pNumber [ i-1 ] ; int nDigit = atoi ( cDigit ) ; if ( nParity == i % 2 ) { nDigit = nDigit * 2 ; } nSum += nDigit/10 ; nSu... | What causes this behavioural difference between C and JavaScript ? |
JS | Question : I use redux-thunk and I want to receive posts . To receive posts I need to get users . So I have doubts about my thunk , Is it right to get all the data in one thunk , if not how to split it into two thunks ? Thunk example : | export default group_id = > { return async dispatch = > { const users = await API.get ( ` /users ? group_id= $ { group_id } ` ) // get users const posts = await axios.all ( [ ... getPosts ( users ) ] ) // get all posts by user ids dispatch ( loadUsersAction ( users ) ) dispatch ( loadPostsAction ( posts ) ) } } | Multiple calls with dependencies redux-thunk |
JS | In JavaScript , is it possible to call an instance method on an object that affects all of its siblings ? For example , say I have the following class : Is it possible for me to create an activateAll method that can activate all of the instances of class Thing ? I need this.active to be an instance variable . | function Thing ( ) { this.active = false ; } Thing.prototype = { constructor : Thing , activate : function ( ) { this.active = true ; } , deactivate : function ( ) { this.active = false ; } } ; | Modifying all members of a class via an instance method |
JS | What 's the difference between these 2 implementations of prototypal inheritance , and considering that we 're working with 2 different `` prototypes '' ( the prototype property that 's only on functions , and the internal prototype ) , and how do these implementations differ in their prototype chain lookup ? Also , do... | function foo ( ) { } foo.prototype.output = function ( ) { console.log ( 'inherits from Function.prototype property ' ) ; } ; bar = new foo ( ) ; bar.output ( ) ; var foo = { output : function ( ) { console.log ( 'inherits from the internal prototype ' ) ; } } ; var bar = Object.create ( foo ) ; bar.output ( ) ; | What 's the difference between these 2 implementations of prototypal inheritance ? |
JS | Please see this minimum example : In this expression , I ca n't simply write thisBecause if variableA = 0 , the result will be differentIs there any way I can simplify this expression ? | const result = ( variableA & & ! variableB ) || ! variableA ; const result = variableA & & ! variableB ; const variableA = 0 ; const variableB = undefined ; console.log ( ( variableA & & ! variableB ) || ! variableA ) ; // trueconsole.log ( variableA & & ! variableB ) ; // 0 | How can I simplify ` ( variableA & & ! variableB ) || ! variableA ` expression in JavaScript ? |
JS | For example : Now consider this : I can override the toString ( ) method , but it does n't really rename the object type . It just kinda fakes it : However , l33t h4x0rs know my toString ( ) method is a lie and I 'm a n00b : What I would like the result to be , regardless of the toString ( ) method being overridden on ... | Object.prototype.toString.call ( new Date ) ; // [ object Date ] Object.prototype.toString.call ( new Array ) ; // [ object Array ] Object.prototype.toString.call ( new Object ) ; // [ object Object ] var PhoneNumber = function ( number ) { this.number = number ; } PhoneNumber.prototype.toString = function ( ) { return... | Is it possible to change the name of an object type in JavaScript ? |
JS | I have a custom shiny input which is a balanced set of sliders . I am trying to use the updateBalancedSliderInput so I can reset the values to their defaults . However , in my app , this updateBalancedSlider function does not kick off any reactives in order to update the outputs . Javascript and shiny example below . M... | # # # Shiny Inputslibrary ( shiny ) balancedSliderInput < - function ( inputId , value = 0 , label = `` '' , group = `` '' , width = `` 100 % '' ) { if ( label ! = `` '' ) label < - paste0 ( ' < label class= '' control-label '' for= '' ' , inputId , ' '' > ' , label , ' < /label > ' ) balanced_slider_tag < - tagList ( ... | Custom Shiny Input Update Reactives |
JS | I have an array like this one : And I would like to get the arrays number mapped to this : Here is the reason:1 : because 14 is the second biggest number0 : because 42 is the biggest number3 : ... What I have tried so far : | let array = [ 14 , 42 , 1 , 3 ] [ 1 , 0 , 3 , 2 ] let sort = ( array ) = > { let result = [ ] let x = array.slice ( 0 ) .sort ( ( a , b ) = > b - a ) for ( let elem of x ) { result.push ( array.indexOf ( elem ) ) } console.log ( result ) } // Workingsort ( [ 14 , 42 , 1 , 3 ] ) // [ 1 , 0 , 3 , 2 ] // Not working , inc... | Get array of array numbers |
JS | I need to get all of the pasted string in input which has a maxLength attribute.But in 'onpaste ' event there is no property to get all of the pasted string.For example , check below snippet with this string : '' AAAAA-BBBBB-BBBBB-BBBBB-BBBBB '' The output is : `` AAAAA '' But I need all of the string . | const onPasteFn = ( e ) = > { setTimeout ( ( ) = > document.getElementById ( `` demo '' ) .innerHTML = e.target.value , 0 ) } < input type= '' text '' maxLength= '' 5 '' onpaste= '' onPasteFn ( event ) '' / > < p id= '' demo '' > < /p > | How to get all of the pasted string , in input which has a maxLength attribute ? |
JS | As I understand objects are passed by reference in JavaScript ( and primitives are passed by value ? ) .This worked similarly with arrays but did not work like I expect with functions : I 'm confused because I thought functions are objects . Should n't the above example return 40 ? | var a , b ; a = { Foo : `` Bar '' } b = a ; a.Foo = `` Other '' ; console.log ( b.Foo ) ; // `` Other '' var a , b ; a = function ( ) { return 20 ; } b = a ; a = function ( ) { return 40 ; } console.log ( b ( ) ) ; // returns 20 ? | Understanding pass by reference vs value with functions |
JS | Possible Duplicate : Are “ ( function ( ) { } ) ( ) ” and “ ( function ( ) { } ( ) ) ” functionally equal in JavaScript ? I 'm reading the document below.http : //addyosmani.com/resources/essentialjsdesignpatterns/book/ # patternityWhen I looked though these examples , self-invoking of an anonymous function had three f... | ( function ( ) { //do something } ) ( ) ; function ( ) { //do something } ( ) ; ( function ( ) { //do something } ( ) ) ; | What 's the difference between these three form of self-invoking anonymous function ? |
JS | I need to do certain action whenever value of one field ( all the same class ) changes . It doe n't work though.I 'm not sure why . I do the exactly same action with ID instead of class and everytnig works fine : The class is specified correctly , because in my function I use $ ( '.payment-amount ' ) .val ( ) and it re... | $ ( '.payment-amount ' ) .change ( function ( ) { ajax_get_supposed_money_left ( ) ; } ) ; $ ( ' # tripsummary-money_begin ' ) .change ( function ( ) { ajax_get_supposed_money_left ( ) ; } ) ; DynamicFormWidget : :begin ( [ 'widgetContainer ' = > 'dynamicform_wrapper_expenses ' , // required : only alphanumeric charact... | Change ( ) does n't react with class identifier |
JS | So , I was working on this challenge to return the third largest number in an array . I had got it worked out until I realized that I must account for repeat numbers . I handled this by adding 3 layers of for loops with variables i , j , and k. You 'll see what I mean in the code . This is not terribly efficient or sca... | function thirdGreatest ( arr ) { arr.sort ( function ( a , b ) { if ( a < b ) { return 1 ; } else if ( a > b ) { return -1 ; } else { return 0 ; } } ) ; for ( var i = 0 ; i < arr.length ; i++ ) { for ( var j = 1 ; j < arr.length ; j++ ) { for ( var k = 2 ; k < arr.length ; k++ ) { if ( arr [ i ] > arr [ j ] ) { if ( ar... | Optimize- get third largest num in array |
JS | This is a xss script : The code between < script > tags will be translated to alert ( 1 ) by the browser and executed.But if I do n't use a < svg > tag the code wo n't be translated to script . Can anyone tell me why this happens ? How does < svg > tag work ? | < svg > < script > & # x61 ; & # x6c ; & # x65 ; & # x72 ; & # x74 ; & # x28 ; & # x31 ; & # x29 ; < /script > < /svg > | Handling of character references in an embedded SVG 's script tags |
JS | ( Let us suppose that there is a good reason for wishing this . See the end of the question if you want to read the good reason . ) I would like to obtain the same result as a for in loop , but without using that language construct . By result I mean only an array of the property names ( I do n't need to reproduce the ... | function getPropertiesOf ( obj ) { var props = [ ] ; for ( var prop in obj ) props.push ( prop ) ; return props ; } function getPropertiesOf ( obj ) { var props = [ ] ; var alreadySeen = { } ; // Handle primitive types if ( obj === null || obj === undefined ) return props ; obj = Object ( obj ) ; // For each object in ... | Obtain the same result as a for..in loop , without any for..in loop |
JS | I am trying to move an object in a way that it rotates as the same direction of the mouse click and also move to the location of the mouse click . So far I arranged movement but I think there is something wrong with the angle because it does not rotate the way I do . Where am I making a mistake ? How can I fix it ? | var theThing = document.querySelector ( `` # thing '' ) ; var container = document.querySelector ( `` # contentContainer '' ) ; var triangle = document.querySelector ( `` # triangle '' ) ; container.addEventListener ( `` click '' , getClickPosition , false ) ; function getClickPosition ( e ) { var xPosition = e.clientX... | Moving and rotating an object according to mouse clickt ? |
JS | I have two express middlwares where one is setting an object to the req and the other that follows it uses that object to turn a switch statement.Here 's an illustration : The comments below reassured me that it 's not an async issue and following the results I 'm getting I 'm lost at what it could be.Edit : The follow... | module.exports = ( req , res , next ) = > { if ( ! req.headers.authorization ) { return res.status ( 401 ) .end ( ) } const token = req.headers.authorization.split ( ' ' ) [ 1 ] return jwt.verify ( token , config.database.jwtSecret , ( err , decoded ) = > { if ( err ) { return res.status ( 401 ) .end ( ) } const userId... | Setting an object on req . in the first of two middlwares seems to not be present at the time the second middlware is called |
JS | I have ownership on A.com ( I wish ... ) I also own B.comis there any HTML tag / Token / code that can Allow B.com to do : top.myFunc ( ) p.s . : I 've seen many question about this topic but none regarding a person owns 2 domains and want to allow this . | ________________| A.com || __________ || | B.com | || |_________| ||________________| | Allow My ( ! ) sites to communicate with Iframe ? |
JS | I 'm using an api to get values to append to the DOM , I have them append to the < tr > tag . my issue is every single time I close the modal and reopen it the table and the values are still there , as well as the `` userCurrency '' on the accordion . How can I remove these elements when I close the modal ? This is my ... | < ! -- currency select -- > < label class= '' '' > < span class= '' '' > Pick a currency < /span > < select id= '' userCurrency '' style= '' display : inline ; width : auto ; vertical-align : inherit ; '' > < option value= '' USD '' > USD < /option > < option value= '' EUR '' > EUR < /option > < option > JPY < /option ... | Removing HTML elements from the DOM using jQuery |
JS | What does Douglas Crockford mean when he wrote the is_array ( ) test saying that it will fail to identify arrays that were constructed in a different window or frame ? Why does the following work across windows and frames ? | var is_array = function ( value ) { return value & & typeof value === 'object ' & & value.constructor === Array ; var is_array = function ( value ) { return value & & typeof value === 'object ' & & typeof value.length === 'number ' & & typeof value.splice === 'function ' & & ! ( value.propertyIsEnumerable ( 'length ' )... | What did Douglas Crockford mean by 'constructed in a different window or frame ' ? |
JS | I ran into a ( bug ? ) with the newest versions of jQuery today where my recursion loop animating background position no longer works . Please see this example : ( this is working with version 1.9 ) http : //codepen.io/bonpixel/pen/qLkgtDelete the cdn jquery and use the codepen bootstrap jquery ( version 1.10.0 ) and i... | < div class= '' blue '' > < div > .blue { width : 100px ; height : 190px ; background : transparent ; url ( http : //2.bp.blogspot.com/-6xJXVFMdC64/TckciX_eI7I/AAAAAAAAAEc/IYORj5mZXiY/s1600/wlk01.gif ) 0 0 repeat-x ; } var backgroundSlidingLeft = function ( ) { $ ( '.blue ' ) .animate ( { 'background-position-x ' : '-=... | Why do the new version ( s ) of jQuery not work with this recursion ? |
JS | When , where and how should i get rid of old event listeners when controller is not relevant anymore ? Consider SPA with two routes : /login and /loggedinProblems : When navigating to /loggedin then loginResponse event keeps listeningWhen navigating back to /login page new listener gets added ( effectively i have 2 lis... | app.factory ( 'socket ' , [ ' $ window ' , function ( window ) { return window.io ( ) ; } ] ) ; app.controller ( 'loginController ' , [ 'socket ' , function ( socket ) { this.tryLogin = function ( credentials ) { socket.emit ( 'login ' , credentials ) ; } sokcet.on ( 'loginResponse ' , function ( data ) { if ( data.sta... | How to clean up events assigned from controller ? |
JS | I 've got a series of rectangles drawn on a canvas and use a scroll event listener to move the boxes up and down.I 'm trying to add in some validation so that the boxes can not be scrolled past a certain point.Due to the acceleration , the scroll values do n't always increment by 1 , so when scrolling quickly , sometim... | lScroll += e.deltaY ; if ( lScroll > 0 ) { canScroll = false ; lScroll = 0 ; } else { canScroll = true ; } | Limit scroll ability on HTML5 canvas elements |
JS | Considering this example : I am wondering if it is possible to simplify what I am doing here.My goal is to test the object-chain this.plantService.plants [ id ] .Name [ 0 ] for validity . However , if I just test if ( this.plantService.plants [ id ] .Name [ 0 ] ) { ... } exceptions are thrown . Any proposals ? : ) | if ( this.plantService.plants [ id ] ) { if ( this.plantService.plants [ id ] .Name ) { if ( this.plantService.plants [ id ] .Name [ 0 ] ) return this.plantService.plants [ id ] .Name [ 0 ] .value ; else return `` ; } else return `` ; } return `` ; | Nice way to test if an object chain in JavaScript is valid |
JS | I found the above function definition from lodash . I am trying to understand it but to no avail.Right inside createMathOperation , I try to log operator and this is the value I guess value and other is 1 and 2 but how ? And how return operator ( value , other ) works when operator is ( augend , addend ) = > augend + a... | function createMathOperation ( operator ) { console.log ( operator ) ; // ( augend , addend ) = > augend + addend return ( value , other ) = > { return operator ( value , other ) } } const add = createMathOperation ( ( augend , addend ) = > augend + addend ) add ( 1,2 ) //3 ( augend , addend ) = > augend + addend | Where is the parameter coming from ? |
JS | I loop through an array of objects that all have a date property . The conditional I set inside the loop to compare the object 's date to today 's date should take care of just a few of the objects in the array I want kept out because of an old date , however , this conditional is removing all objects in the array for ... | constructor ( public navCtrl : NavController , public modalCtrl : ModalController , public loading : LoadingController , public popoverCtrl : PopoverController , public getPostSrvc : getPostsService ) { this.listOfEvents = [ ] ; let that = this ; function getPostsSuccess ( listOfEventsObject ) { for ( var i in listOfEv... | how to keep objects with an old date out of my array |
JS | I created two web-components and nested one of them into the other.Both of them have its constructor . The problem that I have is that , I have no control on running the sequence of the constructors.Is there any way which I can set this out ? Here 's my code : child web component : parent web component : index.htmlThe ... | ( function ( ) { const template = document.createElement ( 'template ' ) ; template.innerHTML = ` < div > WC1 < /div > ` ; class WC1Component extends HTMLElement { constructor ( ) { super ( ) ; console.log ( 'WC1 : constructor ( ) ' ) ; var me = this ; me._shadowRoot = this.attachShadow ( { 'mode ' : 'open ' } ) ; me._... | How can I specify the sequence of running nested web components constructors ? |
JS | I need to find find/replace or convert pilcrow / partial differential characters in a string as they currently show as �.What I thought would work but does n't : But returns empty.To be honest , I 'm not even sure how to achieve what I need to do . | const value = 'Javascript Regex pattern for Pilcrow ( ¶ ) or Partial Differential ( ∂ ) character ' ; const matches = value.match ( /\u2029/gmi ) ; console.log ( matches ) ; | Regex pattern for Pilcrow ( ¶ ) or Partial Differential ( ∂ ) character |
JS | I 've come across some code that has this sort of pattern in numerous places : but it seems to me just a more verbose way of typingThe pattern sometimes appears inside a function which is provided as a callback . It happens to use Backbone , in case that 's relevant . Something like this : Does the pattern actually hav... | this.someFunction.call ( this , param ) ; this.someFunction ( param ) Backbone.View.extend ( { // other stuff ... someFunction : function ( param ) { // ... } , anotherFunction : function ( ) { this.collection.on ( `` some_event '' , function ( ) { this.someFunction.call ( this , param ) ; } ) ; } } ) ; | What is the purpose of this.someFunction.call ( this , param ) ; |
JS | I 'm trying to write a `` switch '' statement but I have strictly defined case and I want to use as little code as I can . So as I was wondering how to do it one thought came to my mind , is it possible to add `` if '' statement in `` switch '' so if this `` if '' statement is true to add more cases to my `` switch '' ... | switch ( myVar ) { case 1 : return 'Your variable is 1 ' ; case 2 : return 'Your variable is 2 ' ; if ( yourVar & & yourVar === true ) { case 3 : return 'Your variable is 3 ' ; } default : return 0 ; } | Can I somehow use if statement in switch to add more cases ? |
JS | I 've been trying to understand how different pointer events ( touch , mouse ) are fired in various browsers/on various devices . On that purposed I have written a tiny webpage for testing events http : //tstr.29pixels.net.A few weeks later I 've run into Mozilla 's event listener test page at http : //mozilla.github.i... | $ ( `` # button '' ) .on ( 'mouseenter mouseleave ... mousemove click ' , function ( e ) { ... } var events = [ 'MSPointerDown ' , 'MSPointerUp ' , ... , 'MSPointerCancel ' ] ; var b = document.getElementById ( 'button ' ) ; for ( var i=0 ; i < events.length ; i++ ) { b.addEventListener ( events [ i ] , report , false ... | Difference between pointer events binding in jQuery and plain Javascript |
JS | I 'm trying to test the following which works manually : Return a list of users as < div > 'sClick a button to reduce that count of < div > 's by one.This does not seem to be working : I 'm confused on why it does this . I clearly get the expected result when testing manually.I think I 'm missing some way to reset that... | it ( `` should show one less person if you tap you liked them '' , function ( ) { var personLength = $ ( '.person ' ) .length ; console.log ( personLength ) ; # > 7 $ ( `` [ data-action=like ] '' ) .first ( ) .click ( ) ; console.log ( $ ( '.person ' ) .length ) ; # > 7 console.log ( Likes.find ( ) .fetch ( ) ) ; # > 1... | Meteor Velocity with Jasmine not returning expecting result ? |
JS | In Javascript , one standard way to declare a function is as follows : However , when I repeat the function name on the right side of the syntax , I get no errors either . What 's going on in the second case ? | var add = function ( a , b ) { return a+b ; } ; var add = function add ( a , b ) { return a+b ; } ; | var NAME = function NAME ( ) { } ; - Function Name used twice |
JS | How would i go about passing the context of $ ( this ) to a plugin ? Currently , i have a plugin ( code as shown below ) Whenthe plugin is called viai get an errorbecause the context of this , is not passed correctly to the plugin 's slideOut ( ) method.I.e the slideOut 's this context is that of the object $ .fn.slide... | ( function ( $ ) { $ .fn.slides= { slideIn : function ( ) { $ ( this ) .fadeIn ( ) .slideDown ( ) ; } , slideOut : function ( ) { $ ( this ) .fadeOut ( ) .slideUp ( ) ; } } } ) ( jQuery ) ; $ ( 'h1 ' ) .click ( function ( ) { $ ( this ) .slides.slideOut ( ) ; } ) ; Uncaught TypeError : Can not read property 'defaultVie... | Passing this 's context to a plugin |
JS | I 'm currently working on a Firefox Add-on that makes use of the Permissions API to request permissions dynamically for specific origins as needed based on the value of a < select > , as the user changes the value , without having a separate submit button . When I call browser.permissions.request the promise is rejecte... | < div id= '' domain-settings '' > Choose your preferred domain : < select > < option > example.com < /option > < option > one.example.com < /option > < option > other.example.com < /option > < /select > < /form > const settings = { domain : 'example.com ' } ; const $ select = $ ( ' # domain-settings ' ) .find ( 'select... | Request permissions using the Permissions API from a < select > onchange handler in Firefox |
JS | Are there any browser restrictions or any other issues that prevents me from doing : versus : I know that apply takes a `` true '' Array as second argument , but passing an arguments collection seems to work just as good . or ... ? | fn.apply ( this , arguments ) ; fn.apply ( this , Array.prototype.slice.call ( arguments ) ) ; | Is it necessary to convert arguments to Array before calling apply ? |
JS | I was using the $ .click ( ) method for triggering some events . But then I needed to set some events for some HTML elements before the elements were declared . Let 's take this as an example : The downside is that when setting the .click ( ) method , the div.hide elements does n't exist , so no trigger is set.So I tur... | < script > $ ( 'div.hide ' ) .click ( function ( ) { $ ( 'div.hide ' ) .css ( { 'display ' : 'none ' } ) ; } ) ; < /script > < div class= '' hide '' > some text < /div > < script > $ ( 'div.hide ' ) .on ( 'click ' , function ( ) { $ ( 'div.hide ' ) .css ( { 'display ' : 'none ' } ) ; } ) ; < /script > < div class= '' h... | unsure about .on ( ) method |
JS | I have a reduce function like below : I tried to transform it like this , but it seems that it is not the correct way : Is there a way to do this or it is not possible . | let el = scopes.reduce ( ( tot , { actions } ) = > tot + actions.length , 0 ) ; let el = scopes.reduce ( ( tot , { actions.length : len } ) = > tot + len , 0 ) ; | React js rename & destructure array length |
JS | I have a number of javascript variables on my page : The ? ? ? ? is assigned a random number by the content management system , so I do n't know the full name of the variable.I 'm looking for any undefined ones.Is there a way in jQuery to loop through all variables that start with opts_ so that I can test them for bein... | var opts_ ? ? ? ? = ... var opts_ ? ? ? ? = ... var opts_ ? ? ? ? = ... | Find a variable using jquery |
JS | I read an article about Test for Internet Explorer in JavaScript which states that a quick test is : But one of the comments showed another way : ( and I have to say , it works ) And so I ask : What is so special with - [ 1 , ] that IE does n't recognize it while others do ? p.s.found another quick falsy-truthy trick | var isMSIE = /* @ cc_on ! @ */0 ; if ( isMSIE ) { // do IE-specific things } else { // do non IE-specific things } if ( - [ 1 , ] ) { // do non IE-specific things } else { // do IE-specific things } IE='\v'== ' v ' | Quick falsy-truthy way of checking IE or not ? |
JS | I 'm just a bit stumped about something at the moment I have the following code which works as expected , everything is fine with it . However I would like to make some minor changes as I would like the following function to be able to insert html markup within the text itself i.e ; So at the moment , this function tak... | var str = `` Let 's get Future Ready ! `` ; var split = str.split ( `` '' ) ; var counter = 0 ; var SI = setInterval ( function ( ) { var typeText = $ ( '.typetext ' ) ; typeText.append ( split [ counter ] ) ; counter++ if ( counter == str.length ) { clearInterval ( SI ) } } ,100 ) | Inserting HTML with JS |
JS | I 'm working on code that is injected on web pages ( using a browser add-on or with a script tag ) .The problem is that we want to use global objects and variables like JSON , window.location , String.split , etc . and the implementation of these may have been changed by the web page . This may make our code fail , and... | > > > String.prototype.split = function ( ) { return 'foo ' ; } ; function ( ) > > > ' a , b , c'.split ( ' , ' ) ; // gives unexpected result '' foo '' | Access original globals and attributes in JavaScript |
JS | So a bit of a hypothetical question ( and do n't hesitate to let me know if there is another post with the same question - I did n't find one though ) So , the .val ( ) method returns the current value of the first element matched by the selector . Is there another `` shorthand '' jquery method that get 's the value of... | var myResult = [ ] ; $ ( `` .myClass '' ) .each ( function ( ) { myResult.push ( $ ( this ) .val ( ) ) ; } ) ; | val ( ) loop possibilities opposed to each ( ) |
JS | I am in the progress to make a roulette game , but i got a problem that my `` animation '' ( or what you call it ) only is able to play once . I dont have so much experiense with javascript and have no idea how to fix my problem . | var img = document.querySelector ( ' # ball ' ) ; ball.addEventListener ( 'click ' , onClick , false ) ; function onClick ( ) { this.removeAttribute ( 'style ' ) ; var deg = 1080 ; var css = '-webkit-transform : rotate ( ' + deg + 'deg ) ; ' ; this.setAttribute ( 'style ' , css ) ; } .roulette { padding-top : 5em ; pad... | Repeat animation after its done javascript css |
JS | I know that an array in JavaScript is nothing else than an object.When I define an array like that : and runI get following array : [ `` 0 '' , `` 1 '' , `` 2 '' ] . Array length of array is 3.When I add a property like : Object.keys ( ) is returning [ `` 0 '' , `` 1 '' , `` 2 '' , `` a '' ] , but array length of array... | var array ; array = [ `` a '' , `` b '' , `` c '' ] ; Object.keys ( array ) ; array [ `` a '' ] = `` d '' ; array [ `` 3 '' ] = `` d '' ; | How to copy array behaviour ? |
JS | I am trying to create a simple snake game . For now I am trying to catch the food but the position of the snake is never the same as the position of food.console.log ( ) will return all positions.jsfiddleAm I calculating something wrong ? Maybe I have to change the variables food_position_x and food_position_y . If not... | ( function ( ) { var canvas = document.getElementById ( 'canvas ' ) , ctx = canvas.getContext ( '2d ' ) , x = 0 , y = 0 , speed = 2 ; x_move = speed , y_move = 0 , food_position_x = Math.floor ( Math.random ( ) * canvas.width ) ; food_position_y = Math.floor ( Math.random ( ) * canvas.height ) ; function eat ( ) { cons... | Let the snake catch his food |
JS | I was reading documentation on toArray ( ) here and testing it out in the console . I can not find the difference between calling toArray ( ) on a selector and calling the selector itself.I got the exact same result both ways , which is an array of DOM elements matching the selector . I even did another testAccording t... | $ ( `` element '' ) .toArray ( ) [ 0 ] === $ ( `` element '' ) [ 0 ] | What is the difference between $ ( `` selector '' ) and $ ( `` selector '' ) .toArray ( ) |
JS | I 'm trying to create a simple ripple effect for a card in my app . It works great , but it is also responding to mouse events outside of its container : Code looks like this : I do n't quite see why it is behaving this way . Any idea ? AddedThis whole page is an independant dom-module . Apparently using paper-ripple i... | < dom-module > ... < template > ... < paper-material > < div class= '' wrapper '' > ... < /div > < paper-ripple > < /paper-ripple > < /paper-material > ... < /template > < /dom-module > | paper-ripple is listening to click events outside of its container |
JS | I know that functions are objects in javascript , and that functions can be assigned to variables . I am also aware of this question : How does the ( function ( ) { } ) ( ) construct work and why do people use it ? .But I would like to know precisely what does it mean in this context : https : //github.com/zsolt/retwis... | User = function ( ) { } | what does function ( ) { } mean when assigned to a variable |
JS | I 'm creating a custom element that will be able to convert its contents from markdown to HTML . However , I 'm not able to get the contents of my custom elements.My issue is in the connectedCallback ( ) . When logging this , I get the whole < mark-down > node with its contents in markdown . However , it does n't seem ... | < ! doctype html > < html > < body > < template id= '' mark-down '' > < div class= '' markdown '' > < /div > < /template > < ! -- Converts markdown to HTML -- > < script src= '' https : //cdn.jsdelivr.net/gh/showdownjs/showdown/dist/showdown.js '' > < /script > < script > customElements.define ( 'mark-down ' , class ex... | How to Get the Contents of a Custom Element |
JS | I saw a weird function that looked something like : The output is 3 , I understand that it 's a function returning a function and both a and b are in the same scope but the questions I have are : How could this be used in real life ? What 's the advantage of not using a function with 2 parameters and using this instead... | const x = ( a ) = > ( b ) = > a + b ; console.log ( x ( 1 ) ( 2 ) ) | Weird function syntax |
JS | I want to move shared functionality from my react components to a higher order component like this : Using this kind of syntax requires to explicitely bind this in the constructor of the HOC : .. but I wanted to bind the wrapped component instead . So what I tried in my wrapped component 's constructor wasBut this just... | function withListFunctions ( WrappedComponent ) { return class extends React.Component { constructor ( props ) { super ( props ) ; } // my shared functionality deleteItem ( ) { // Do something , then ... this.setState ( { itemDeleted : true } ) ; } render ( ) { return ( < WrappedComponent deleteItem= { this.deleteItem ... | `` this '' in react higher order component |
JS | In Java , I am generating a string with letters A and B with a COMBINING OVERLINE U+0305 character in between.I get this in IDEA : But if I copy to here , it will become A̅B.This one is from the Chrome console : I was confused by the combining character 's combining order . Which one is correct ? I was writing this in ... | @ Testpublic void test ( ) { System.out.println ( `` A\u0305B '' ) ; } | Why is Unicode combining character order different between IDEA and Chrome ? |
JS | In fact the title does not fully cover what I 'm after . I have created my own select element . It 's made of some div , ul/li and hidden input elements.It 's of course got the markup and javascript part . Here 's the html : The javascript code is just a bunch of functions that catch events like click , hover , keyup e... | < div id= '' ddlCars '' class= '' ma-select '' style= '' width:350px ; '' > < div class= '' ma-select-box '' > < input class= '' ma-select-box-filter '' type= '' text '' > < /div > < div class= '' ma-select-options '' > < ul class= '' ma-select-ul '' > < li class= '' ma-select-li ma-visible-option '' optvalue= '' 7 '' ... | How can I add a property to my custom element and be able to fire an action on its value change |
JS | I 'm working on a shop administration with react , alt and immutable . My offer object looks more or less like this : I iterate over every entry and display a form to edit the group , article , ... . If something is changed I call an OfferAction and pass the path , changed field and new value to the entity e.g . OfferA... | offer : { groups : [ { articles : [ { optionGroups : [ { options : [ ] } ] } ] } ] } | Best practice : reuse components or write duplicates |
JS | I am learning javascript and I am wondering about the concept of functions and prototypes inside an object.My understanding of the conceptAs I understand it , functions should be attached to object 's prototype in order to allocate less memory.For example ( if what I said is true ) , both version will do the same job b... | var collectionOfObjects = [ ] ; for ( var i=0 ; i < 1000 ; i++ ) { collectionOfObjects.push ( { id : 2 , sayHi : function ( ) { console .log ( 'hi ' ) } } ) } //vsfunction Foobar ( id ) { this.id = id || 0 ; } Foobar.prototype.sayHi = function ( ) { console.log ( 'hi ' ) ; } var otherCollection = [ ] ; for ( var i=0 ; ... | Should functions be attached to object or its prototype ? |
JS | As far as I can tell , there are two main ways of creating functions for an object in javascript . They are : Method A , make it in the constructor : Method B , add it to the prototype : Obviously if you did : then myFunc3 would become associated with MyObject itself , and not any new objects created with the new keywo... | function MyObject ( ) { this.myFunc1 = function ( ) { ... } this.myFunc2 = function ( ) { ... } ... } function MyObject ( ) { ... } MyObject.prototype.myFunc1 = function ( ) { ... } MyObject.prototype.myFunc2 = function ( ) { ... . } MyObject.myFunc3 = function ( ) { ... . } | Creating functions for an object in javascript |
JS | I have a library which uses lets say `` getAttribute '' function of Node a lot . So instead of having it as node.getAttribute ( ) , if I have node [ getAttributeStr ] ( ) , I can have the getAttributeStr as a local string value `` getAttribute '' , which would get minified reducing the size of the code . My question is... | var getAttributeStr = `` getAttribute '' ; node [ getAttributeStr ] ( `` abc '' ) | Dynamic variables instead of static causes JS to be slow ? |
JS | This is my javascript function to open a jquery dialog . How can I hide the part show : 'slide , from IE ? | ( ' # dialog ' ) .append ( iframe ) .appendTo ( `` body '' ) .dialog ( { autoOpen : false , modal : true , resizable : false , show : 'slide ' , width : 800 , height : 700 , close : function ( ) { } } ) ; $ ( ' # dialog_click ' ) .click ( `` callback '' , function ( ) { $ ( ' # dialog ' ) .dialog ( 'open ' ) ; return f... | how can I hide a part of javascript from IE |
JS | Simple question really , I 'm running a bunch of timeouts but wan na make sure they do n't slow the page down and that for some reason they are n't kept in memory after they 've executed.My guess is that they 're destroyed once they 've run but just want to follow best practice . | $ projects.each ( function ( index ) { var $ this = $ ( this ) ; window.setTimeout ( function ( ) { // animate } , 300 * index ) ; } ) ; // Clear timeouts ? | Do I have to clear setTimeouts after they 've run ? |
JS | I have a simple html link , in which I call a JavaScript function onClick and try to switch the value taken in . It 's not working.Here is my code : | function lang ( language ) { switch ( language ) { case `` it-IT '' : alert ( `` Italiano selezionato '' ) ; break ; case `` en-US '' : alert ( `` English selected '' ) ; break ; } } < p > < a href= '' # '' onClick= '' lang ( 'en-US ' ) ; '' > English < /a > < /p > < p > < a href= '' # '' onClick= '' lang ( 'it-IT ' ) ... | JavaScript function does not work when used inside onclick attribute |
JS | Can I preserve a copy of an object , inside that object when its createdThis is my function which creates a new student object : I would like to create a copy of the object when it is initialized inside that object : I came up with this : But the problem is its giving me a infinite loop of copies of current object in b... | function student ( id , name , marks ) { this.id = id ; this.name = name ; this.marks = marks ; } function student ( id , name , marks ) { this.id = id ; this.name = name ; this.marks = marks ; this.baseCopy = this ; } | Can I preserve a copy of an object , inside that object when its created |
JS | I have a 'yesno ' input radio . When user clicks yes , a yesDiv is shown , and when user clicks no , noDiv is shown . In order to implement that I created the object myObject . This works , I know that I ca n't use this to refer to the object 's properties inside the method 'switchDiv ' because of the scope of 'this ' ... | var myObject= { init : function ( config ) { this.config=config ; this.config.InputRadio.bind ( 'click ' , this.config , this.switchDiv ) ; } , switchDiv : function ( ev ) { self=ev.data ; if ( $ ( this ) .val ( ) ==1 ) { self.divYes.hide ( ) ; self.divNo.show ( ) ; } else { self.divYes.show ( ) ; self.divNo.hide ( ) ;... | Better design in order to refer to the own object 's properties from an object 's method |
JS | I 'm trying to update the value attribute of a button inside a table cell . I 'm iteration over each cell and my code looks like this : But this does n't work . My 'cell ' looks like this : So i want to change `` some stuff '' .Any help would be greatly appreciated . | for ( var i = 0 , cell ; cell = table.cells [ i ] ; i++ ) { $ ( cell ) .find ( '.btn btn-default ' ) .val ( `` new value '' ) ; } < div class=\ '' list-element\ '' > < a class=\ '' glyphicon glyphicon-link\ '' href=\ '' www.somelink\ '' > < /a > < input class=\ '' btn btn-default\ '' type=\ '' button\ '' value=\ '' som... | I need help accessing a button inside a div |
JS | I 'm wondering if it 's possible to access a condition 's value directly like the following example.This would also make ternary operators less bloatyThanksEDIT : Clearing this question up for any future visitors.Basically this question is about retrieving the resulting value of what is evaluated in an if/else statemen... | var a = [ `` pear '' , `` kiwi '' , `` orange '' , `` apple '' ] if ( a.indexOf ( `` orange '' ) ! == -1 ) { console.log ( this ) //as a.indexOf ( `` orange '' ) has been evaluated already above this prints 2 } var a = [ `` pear '' , `` kiwi '' , `` orange '' , `` apple '' ] var b = ( ( a.indexOf ( `` orange '' ) ! == ... | Using the conditions value in if/else |
JS | I 'm on my journey to learn Object-Oriented Programming in Javascript.I got this video lession from here http : //www.objectplayground.com/ which I understood quite a bit the prototypal method over classical method.While watching the lession , I was paused by the example shown for the classical method to work with subc... | //superclassfunction Answer ( value ) { this._val = value ; } //define prototype property 'get ' for the superclassAnswer.prototype.get = function fn1 ( ) { return this._val ; } //subclassfunction FirmAnswer ( value ) { Answer.call ( this , value ) ; } FirmAnswer.prototype = Object.create ( Answer.prototype ) ; FirmAns... | How ` this ` works from a Classical Method of Prototyping in Javascript |
JS | When trying to access the property a of the object { } I get the errorWith parens all is fine : Why do I get an error in the fist place ? Is there ambiguity ? | { } .a SyntaxError : Unexpected token . ( { } ) .a | Why does accessing a property directly on an Object literal throw a SyntaxError ? |
JS | I want to get some data from a form making AJAX call . I am getting the data as a string in my PHP page . The string looks like 'fname ' : 'abc ' , 'lname ' : 'xyz ' , 'email ' : '' , 'pass ' : '' , 'phone ' : '' , 'gender ' : '' , 'dob ' : ''Now I want to convert this entire string into array which would look like [ `... | fname = $ ( `` # form-fname '' ) .val ( ) ; lname = $ ( `` # form-lname '' ) .val ( ) ; email = $ ( `` # form-username '' ) .val ( ) ; pwd = $ ( `` # form-password '' ) .val ( ) ; phone = $ ( `` # form-phone '' ) .val ( ) ; gender = $ ( `` # form-gender '' ) .val ( ) ; dob = $ ( `` # form-dob '' ) .val ( ) ; var user =... | Get JSON data from ajax call to PHP page through POST |
JS | So I 'm planning to separate my functions into separate files and then import them into a single index.js which then becomes the main exporter . So I 'm wondering if having something like var bcrypt = require ( 'bcrypt ' ) in several of my files be slower than just having it in one file.Here 's how I 'm planning to gro... | const fs = require ( 'fs ' ) ; const path = require ( 'path ' ) const modules = { } const files = fs.readdirSync ( __dirname ) files.forEach ( file = > { if ( file === 'index.js ' ) return let temp = require ( path.join ( __dirname , file ) ) for ( let key in temp ) { modules [ key ] = temp [ key ] } } ) ; module.expor... | Does having the same ` require ` in multiple files increase runtime |
JS | I ran a script through JSLint and it picked out a specific issue with parenthesis placement.I had written : And it was suggested to use : I 'm curious as to what bugs or issues this particular change fixes . I would assume that because JSLint picked it out as an issue , there must be an issue for someone.Expanded forms... | ( function ( ) { } ) ( ) ; ( function ( ) { } ( ) ) ; ( function ( p ) { ... code ... } ) ( param ) ; //parameters after the parens ( function ( p ) { ... code ... } ( param ) //parameters within the parens ) ; | How should closures be formatted ? |
JS | Sorry for the incredibly lame question , but as a brand new programmer all the answers I 've found while searching all day are for other problems not specific to me so I decided I 'd post about it.I have taken it upon myself to convert a sample `` Random Quote Generator '' program I found into a small web based app tha... | < html > < head > < title > Simpsons Episode Generator < /title > < /head > < body > < h1 > Simpsons Episode Generator < /h1 > < br > < img src= '' https : //vignette2.wikia.nocookie.net/simpsons/images/9/97/Mr_Burns_-_the_box.jpg/revision/latest ? cb=20121215235014 '' alt= '' Mr Burns box '' > < div id= '' linkDisplay... | Convert a line of text generated in a javascript file into a clickable link in HTML |
JS | So , I 've got an Angular app that makes restful calls to the server . There is a service that wraps up the calls to the server . I currently have a method on the service that simply returns the promise from the $ http service . I 'd like to add some additional processing on that method call , but I 'm not sure how to ... | class BoardService { private $ http ; constructor ( $ rootScope : IRootScope , $ http : ng.IHttpService ) { this. $ http = $ http ; } fetchBoard ( id : number ) { return this. $ http.get ( `` /api/board/ '' + id ) ; } } fetchBoard2 ( id : number ) { this. $ http.get ( `` /api/board/ '' + id ) .success ( function ( data... | Angular Service Promises |
JS | I have created the tree like structure using appendChild ( ) in JavaScript.When clicking add button a root node gets added . When clicking root node a parent node gets added . When clicking parent node a child node gets added.Now I am trying to delete that add by adding a small icon . On clicking that icon that particu... | function remove_div ( ) { var A = document.getElementById ( 'test-0 ' ) ; A.parentNode.removeChild ( A ) ; } div1.id = 'test- ' + document.querySelectorAll ( '.ui-modal > .msg1 ' ) .length ; function add_div ( ) { var div1 = document.createElement ( 'ul ' ) ; document.body.appendChild ( div1 ) ; div1.className = 'ui-mo... | How to delete the parent node that has the id generated automatically ? How to specify that id ? |
JS | Possible Duplicate : Is Chrome 's JavaScript console lazy about evaluating arrays ? Chrome 's js console is showing an array with a deleted value before the value is deleted . Why ? jsFiddle that demonstrates this behavior. | var list= [ ] ; list.push ( `` one '' ) ; list.push ( `` two '' ) ; list.push ( `` three '' ) ; console.log ( list ) ; // [ `` two '' , `` three '' , undefined × 1 ] $ ( `` # output '' ) .append ( JSON.stringify ( list ) ) ; // [ `` one '' , '' two '' , '' three '' ] list.shift ( ) ; $ ( `` # output '' ) .append ( $ ( ... | Why is Chrome showing a value as being removed from an array before it has been ? |
JS | This is more a theoretical question than a practical one . It 's about the parsing of some code delimited by curly braces.Here are two examples of object initializers : Here are two examples of blocks : In practice , it seems that { ... } makes a block apart if the precedent code requires an expression.But I 've never ... | f ( { } ) ; ( { a:3 } ) ; { } { a:3 ; } | Differentiate a block from an object initializer |
JS | Very frequently I find in the logs requests for javascript that are not part of my website.One such javascript is `` showpass-1.5.js '' and error looks like : I 'm thinking that someone injects arbitrary code into the html of my website and tries to collect information about my users . But who and in what circumstances... | 2015/12/06 07:03:27 [ error ] 14129 # 0 : *54208136 open ( ) `` /usr/share/nginx/html/nsl.mapticket.net/sd/apps/showpass/showpass-1.5.js '' failed ( 2 : No such file or directory ) [ ... ] | injecting javascript in my html |
JS | I am working to convert my simple JavaScript Donut Chart into a jQuery Plugin.It is my first jQuery plugin and I could use some help in a couple place please ... Demo of what I have so far : http : //jsfiddle.net/jasondavis/qsgqebox/Below is the JavaScript I have so far.jQuery Usage : What I need help with : 1 ) It cur... | jQuery.fn.updatePercentageGraph = function ( options ) { var settings = $ .extend ( { // These are the defaults . percent : 0 , } , options ) ; var percent = settings.percent ; if ( typeof percent === 'undefined ' ) { var percent = parseInt ( this.data ( 'percent ' ) ) ; } else { if ( percent === `` ) { var percent = p... | Update jQuery plugin to build HTML and prevent it from rebuilding on multiple calls |
JS | The below call returns 24:00 in latest Chrome & Opera , while it previously returned 00:00 , is this a by design behavior ? | const [ , time ] = new Date ( 2020 , 1 , 1 , 0 , 0 ) .toLocaleDateString ( `` en-us '' , { hour12 : false , hour : `` 2-digit '' , minute : `` 2-digit '' } ) .split ( `` , `` ) ; console.info ( time ) ; // 24:00 | toLocaleDateString returns unexpected formatted time |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.