This is callParent method in ExtJS. What are $previous, $owner, and $name? Why is there a leading "$" sign?
callParent: function(args) {
var method;
// This code is intentionally inlined for the least number of debugger stepping
return (method = this.callParent.caller) && (method.$previous ||
((method = method.$owner ? method : method.caller) &&
method.$owner.superclass.$class[method.$name])).apply(this, args || noArgs);
}
It's internal detail the class system sets up so it can track methods. The $ are there so it's less likely to conflict with your own property names on the class.
Related
I'm using angular.resource js
There I'm trying to access get service which has query param triggered from a form search.
If user search with only "#" in input field, it goes as query param which starts with "#" character then getting above exception
Thanks in advance.
Because of below code in angular.resource js
// Helper functions and regex to lookup a dotted path on an object
// stopping at undefined/null. The path must be composed of ASCII
// identifiers (just like $parse)
var MEMBER_NAME_REGEX = /^(\.[a-zA-Z_$#][0-9a-zA-Z_$#]*)+$/;
function isValidDottedPath(path) {
return (path != null && path !== '' && path !== 'hasOwnProperty' &&
MEMBER_NAME_REGEX.test('.' + path));
}
function lookupDottedPath(obj, path) {
if (!isValidDottedPath(path)) {
throw $resourceMinErr('badmember', 'Dotted member path "#{0}" is invalid.', path);
}
var keys = path.split('.');
for (var i = 0, ii = keys.length; i < ii && angular.isDefined(obj); i++) {
var key = keys[i];
obj = (obj !== null) ? obj[key] : undefined;
}
return obj;
}
If you really want ot make this as your url params. Try escape the # char as this has special meaning in $resource library
Normally it happens when we have only # as the value, where it searches for the value of string after "#" in the request body.
As it is a get method, where angular resource ignores it. Very weird behavior.
AngularJs doc: https://code.angularjs.org/1.5.11/docs/api/ngResource/service/$resource
If the parameter value is prefixed with #, then the value for that parameter will be extracted from the corresponding property on the data object (provided when calling a "non-GET" action method). For example, if the defaultParam object is {someParam: '#someProp'} then the value of someParam will be data.someProp. Note that the parameter will be ignored, when calling a "GET" action method (i.e. an action method that does not accept a request body)
So before calling any method in resource try escape the # symbol:
paramValue = paramValue.replace(/#/gi, '\\#');
And again you can remove the scape before api call happens in request method of interceptor service for $httpProvider.
configParams = configParams.replace(/\\#/gi, '#');
Let me know if need any more help.
Thanks
I have a annidate variable like that.
$scope.a = { b: {c : 1} };
var test = $scope.a.b.c;
// test == 1
$scope.a = {}
var test = $scope.a.b.c;
// ERROR
I want test variable will be null or undefined.
How can I fill test variable without error?
some advice?
I'm looking for a smart way
not only
if(angular.isDefinied($scope.a) && angular.isDefinied($scope.a.b) && angular.isDefinied($scope.a.b.c))
You probably want to do something like that:
var test = ($scope.a && $scope.a.b && $scope.a.b.c) ? $scope.a.b.c : undefined;
If you are not defined the value before using it, then definitely, it will throw an error. You must define or you must check whether it is defined or not. Otherwise you can't resolve the error. var test will get a value only if there is no error. Now, its up to you to decide and use a smart way
var test = $scope.a?((typeof($scope.a.b)=="object" && $scope.a.b.c)?$scope.a.b.c:(typeof($scope.a)=="object" && $scope.a.b)?$scope.a.b:null):null
I have a question about naming SharedSizeGroups in WPF grids mostly out of curiosity. I noticed on MSDN that they list restrictions for the group's string name:
The SharedSizeGroup property value must satisfy the following rules:
Must not be empty.
Must only consist of letters, digits, and underscore characters.
Must not start with a numeric value.
I have some groups that I named numerically ("1", "2", "3", etc.) and have never had a problem with them. Just for kicks I renamed some groups to something like ",-[]" and they still worked too. So these rules are not enforced and seemingly not necessary. Does anybody know the reason for the rules in the documentation? Is it possible for the names to conflict with something that WPF is doing internally?
Edit: Okay, so WPF does enforce it after all, validation just doesn't fire in my non-compiled templates.
Interesting, I took a look at the DefinitionBase class in reflector and the SharedSizeGroup property.
It creates a dependency property with a validation callback defined as the following:
SharedSizeGroupProperty = DependencyProperty.Register("SharedSizeGroup", typeof(string), typeof(DefinitionBase), new FrameworkPropertyMetadata(new PropertyChangedCallback(DefinitionBase.OnSharedSizeGroupPropertyChanged)), new ValidateValueCallback(DefinitionBase.SharedSizeGroupPropertyValueValid));
private static bool SharedSizeGroupPropertyValueValid(object value)
{
if (value == null)
{
return true;
}
string str = (string)value;
if (str != string.Empty)
{
int num = -1;
while (++num < str.Length)
{
bool flag = char.IsDigit(str[num]);
if (((num == 0) && flag) || ((!flag && !char.IsLetter(str[num])) && ('_' != str[num])))
{
break;
}
}
if (num == str.Length)
{
return true;
}
}
return false;
}
I tested this, and it does in fact return false for anything containing non-numeric, non-alpha, non-underscore characters. It also returns false for any group starting with a number. So it seems to follow general variable name rules..
My guess is this would most likely throw some sort of exception, but perhaps it is being handled. Have you checked the output window?
I tried an invalid name, and I got an XAMLParseException.
have the following function on my collection:
getFiltered: function (status, city) {
return this.filter(function (trainer) {
return ((status === null) ? trainer : trainer.get("TrainerStatusName") === status) &&
((city === null) ? trainer : trainer.get('City') === city);
});
}
What is is best way to deal with nullable params passed in i.e. if city it null then ignore filter/fetch all and if status is null then ignore filter/fetch all
The code above works, but curious about alternatives
Ok, first off, I'm a little confused by your question; the title says its about handling "nullable" parameters, but your code looks like it is dealing with "special case" parameters (specifically "all") ... except for the case of trainer being null, but I don't think that is even possible when iterating through a Backbone collection.
* * Edit * *
OP updated the question, so the above is no longer relevant. I've also updated my answer accordingly.
In any case, there's nothing at all wrong or unusual about your code; ternary operators are a standard way of handling one-off special cases. If you're looking for alternative ideas though, here's one that uses an extra function to DRY out (eliminate the duplication of) your code:
function matchesOrAll(expected, actual) {
return expected === null || expected === actual;
}
getFiltered: function (status, city) {
return this.filter(function (trainer) {
return matchesOrAll(status, trainer.get("TrainerStatusName") &&
matchesOrAll(city, trainer.get("City"));
}
* * Edit * *
Now that we're talking about null and not "all", it's worth pointing out that there is a better pattern for simpler cases of nulls/undefined. If you were just filtering cities, for instance, the code could just be:
getFiltered: function (expectedCity) {
return this.filter(function (currentCity) {
return expectedCity === (currentCity || expectedCity);
}
In other words, you could take advantage of Javascript's "truthiness", and the fact that disjunctive (ie. ||) booleans expressions return the first truthy value. This eliminates the need for a ternary, and many libraries use this pattern to fill in un-provided arguments; for instance, here's a line from jQuery that sets the "target" argument to a new object if none is provided:
target = arguments[1] || {};
Unfortunately though, when you're dealing with properties/attributes of things (eg. trainer.get('foo')) instead of just objects directly (eg. trainer), there's no good shortcut you can use (other than making a function).
I want to declare a global variable like var i=0; in extjs 3.4. in order to check the maximum occurences of '?' inside keypress listner. How can i do that.
Code:
keypress: function(combo, e) {
var i = 0;
var charCode = e.getCharCode();
if ( e.shiftKey && charCode === 63 ) {
i = i+1;
if(i=== 3){
alert('max three ?s allowed');
}
}
}
}
Here every time i is becoming zero so i want to declare i as global.
Raj
If you tend to use MVC structure for your application, simply define them in app.js
Note: To my experience, global variable should be meaningful and uppercase. For example:
var MY_GLOBAL_VARIABLE = some_value;
Using Global variable is Generally a bad idea.
If I were you I'd wrap up the variables I needed to share in a singleton.
PHP Code:
Ext.define('SaherdData', {
singleton: true,
txt: 'myvalue',
meh: 42
});