ES6 unexpected token - ecmascript-6

I'm trying to use es6 to keep this code a little cleaner however my code creates a fatal error unexpected token. What am I doing wrong here?
Example: Works - old javascript
('/admin/candidate_profile/edit/contact_details/' + this.props.candidateUserId)
Example: Doesn't work - es6
{`/admin/candidate_profile/edit/contact_details/${this.props.candidateUserId}`}

If you are trying to set a variable equal to the above statement then you don't need the curly braces. For example, the below snippet should work:
let foo = `/admin/candidate_profile/edit/contact_details/${this.props.candidateUserId}`;

Related

Syntax error when calling a function with parameters in slim template

I have a slim template where I call a function like so:
textarea.form-control value = #function(parameter)
However I get the following error:
syntax error, unexpected '(', expecting ')'
Its strange that it does not like the '(" character because that's how I would imagine we would call functions with arguments from a template. What am I doing wrong and how can I call a function with an argument from a slim template. Apologies if this is a basic question, I am very new to slim and ruby
You don’t need the #:
textarea.form-control value = function(parameter)
As long as function and parameter are defined then this should work.
You may be confusing Ruby attributes (which use #) with functions/methods (which don’t). If you want to pass an attribute as the parameter, then you need the # in front of its name:
textarea.form-control value = function(#attribute)

IDL Function Is Reluctant To Define

Happy Monday Everyone!
So. I'm really, really new to IDL. I need to translate a program I have written in Python to IDL, and I can barely get it started.
I am trying to define a function, but I am given the following error each time I try to compile it.
% Compiled module: OSTN02.
% Compiled module: OSTN02.
% Attempt to call undefined procedure: 'OSTN02'.
% Execution halted at: $MAIN$
I have tried following the guide from Harris Geospatial, but I am getting nowhere.
The code is below:
FUNCTION OSTN02, DATA, EASTCOL, NORTHCOL
;MAY NEED TO ADD FILLNaN HERE
DATAFILE = READLIS(FILE = !DATA_DIR + 'PROJECT ONE/OSTN15_OSGM15_DataFile.CSV', SEP = ',')
RETURN, DATAFILE
STOP
END
Any help is much appreciated. Thank you.
The error message is telling you:
% Attempt to call undefined procedure: 'OSTN02'.
You have defined a function, but IDL is looking for a procedure (because you are calling it as a procedure). The call to your function should be:
datafile = ostn02(data, eastcol, northcol)
although you aren't using those parameters, so you might want to remove them from your function.

Robot framework: Retrieving keys that contain dashes from a dict

I am new to Robot Framework and am trying to validate the contents of some JSON that is returned from a web service. The problem is that some attributes of the json objects have dashes in them and Robot doesn't seem to like this. I have something like the following
&{deployment} = list deployment ${deployment_name}
&{changeSets} = Set Variable ${deployment.ChangeSets}
&{myChangeSet} = Set Variable ${changeSets.my-change-set}
Should Be True ${myChangeSet.UseLocal}
Should Be Equal As Strings ${myChangeSet.Version} ${update_version}
But Robot fails on the 3rd line with the following error:
Resolving variable '${changeSets.my-change-set}' failed: AttributeError: my
I tried to escape the dashes but that still doesn't seem to work:
Resolving variable '${changeSets.my\-change\-set}' failed: SyntaxError: unexpected character after line continuation character (<string>, line 1)
I can't seem to find any information in the Robot docs with other ways to retrieve dict keys outside of the dot-notation. Any suggestions?
The use of dot notation is just a convenience. You can still access them the normal way (documented in the dictionary variables section of the user guide as &{NAME}[key]):
&{changeSets}[my-change-set]
Or, with extended variable syntax, which treats everything inside {} as a python expression:
${changeSets['my-change-set']}
Here is a working example illustrating these two methods:
*** Variables ***
&{changeSets} my-change-set=foo
*** Test Cases ***
Test 1
should be equal ${changeSets['my-change-set']} foo
Test 2
should be equal &{changeSets}[my-change-set] foo

AXE - Asp Xtreme Evolution - Json parser for classic asp

Has anyone ever used this and got it working? I'm having real problems because it's telling me there is a JScript error and I'm not sure how to fix it.
Links on this are here to get some background on the product, but it's a JSON parser for classic asp.
Iterating though a JSON return using ASP Xtreme Evolution
I'm sure I had this working the other other day, but now I've come back to it, it's throwing a JScript error, and I can't seem to make it work now.
So, I'm posting JSON to a classic asp page, this is the code I'm using to include the json2.asp page as instructed in all the tutorials:
<%#LANGUAGE="VBSCRIPT"%>
<!--#include file="json2.asp"-->"%>
<% 'json processing details here..
The error it throws is on a line of json2.asp and it's a JScript error. Here is the exact error:
Microsoft JScript compilation error '800a03ea'
Line 765 json2.asp
I believe this is a version of Crockfords json2.js and I think the reason it's in an asp page is so it can use JScript, but it's not progressing for me. Anyone have any idea what I'm talking about that could help me out before I tear all my hair out?!
Let me know if you need more info - many thanks
UPDATE
Here is line 765 (in the middle between the comments)
if (/^[\],:{}\s]*$/.
test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '#').
replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').
replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
// In the third stage we use the eval function to compile the text into a
// JavaScript structure. The '{' operator is subject to a syntactic ambiguity
// in JavaScript: it can begin a block or an object literal. We wrap the text
// in parens to eliminate the ambiguity.
j = eval('(' + text + ')');
// In the optional fourth stage, we recursively walk the new structure, passing
// each name/value pair to a reviver function for possible transformation.
return typeof reviver === 'function' ?
walk({'': j}, '') : j;
}
You're not including the right things. You need the whole library available and to include the following files (change your paths appropriately).
<!-- #include file="includes/extlib/axe/base.asp" -->
<!-- #include file="includes/extlib/axe/classes/Parsers/json.class.asp" -->
Then to actually use, you do something like this:
set oJson = new Json
oJson.loadJson(strJSON)
strSomething = oJson.getElement("theElement")
set oJson = nothing
All this taken from working code.

Is there a way to avoid using 'call' in Coffeescript?

I'm writing a simple Twitter client to play with coffeescript. I have an object literal with some functions that call each other via callbacks.
somebject =
foo: 'bar'
authenticateAndGetTweets: ->
console.log "Authorizing using oauth"
oauth = ChromeExOAuth.initBackgroundPage(this.oauthdetails)
oauth.authorize( this.afterLogin.call this )
afterLogin: ->
this.getTweets(this.pollinterval)
This code works perfectly. Edit: actually this.afterlogin should be sent as a callback above, not ran immediately, as Trevor noted below.
If, within authenticateAndGetTweets, I removed the 'call' and just ran:
oauth.authorize( this.afterLogin )
and don't use 'call', I get the following error:
Uncaught TypeError: Object [object DOMWindow] has no method 'getTweets
Which makes sense, since 'this' in afterLogin is bound to the thing that initiated the callback rather than 'someobject' my object literal.
I was wondering if there's some magic in Coffeescript I could be doing instead of 'call'. Initially I thought using the '=>' but the code will give the same error as above if '=>' is used.
So is there a way I can avoid using call? Or does coffeescript not obviate the need for it? What made '=>' not work how I expected it to?
Thanks. I'm really enjoying coffeescript so far and want to make sure I'm doing things 'the right way'.
As matyr points out in his comments, the line
oauth.authorize( this.afterLogin.call this )
doesn't cause this.afterLogin to be called as a callback by oauth.authorize; instead, it's equivalent to
oauth.authorize this.afterLogin()
Assuming that you want this.afterLogin to used as a callback by oauth.authorize, megakorre's answer gives a correct CoffeeScript idiom. An alternative approach supported by many modern JS environments, as matyr points out, would be to write
oauth.authorize( this.afterLogin.bind this )
There's no CoffeeScript shorthand for this, partly because Function::bind isn't supported by all major browsers. You could also use the bind function from a library like Underscore.js:
oauth.authorize( _.bind this.afterLogin, this )
Finally, if you were to define someobject as a class instead, you could use => to define afterLogin such that it's always bound to the instance, e.g.
class SomeClass
foo: 'bar'
authenticateAndGetTweets: ->
console.log "Authorizing using oauth"
oauth = ChromeExOAuth.initBackgroundPage(this.oauthdetails)
oauth.authorize(this.afterLogin)
afterLogin: =>
this.getTweets(this.pollinterval)
someobject = new SomeClass
you can put a lambda in the function call like so
auth.authorize(=> #afterLogin())
You have to use either the call or apply methods because they set the scope of the function (the value of this). The error results because the default scope is the window object.