Reputation: 4214
In Javascript functions can be arguments of a constructor but I would like to assign a conditional value to be evaluated when a new object is created.
var obj = {
prop: function(){ return 1; },
prop2: "asd"
};
console.log(obj.prop); // This prints "function() ..."
With this method, Is there any way to make prop value 1 ?
For those of you wondering why I want to do this, I have the following code and I need to pass a different offset parameter if some condition is true or not.
$('#primary-menu > ul > li > a[href*=#]').smoothScroll(
{ preventDefault: true, easing: 'swing', speed: 700, offset: -200, exclude: ['.external a'],
beforeScroll: function () {
// Disable all waypoints on internal divs which are linked to from the menu
$('#primary-menu > ul > li > a[href*=#]').each(function () {
var element_id = MO_THEME.get_internal_link($(this).attr('href')); // Gives me ids of div's with ids like #work,#service, #portfolio etc.
$(element_id).waypoint('disable');
});
},
afterScroll: function () {
// Enable all waypoints on internal divs which are linked to from the menu
$('#primary-menu > ul > li > a[href*=#]').each(function () {
var element_id = MO_THEME.get_internal_link($(this).attr('href')); // Gives me ids of div's with ids like #work,#service, #portfolio etc.
$(element_id).waypoint('enable');
});
}});
Upvotes: 0
Views: 61
Reputation: 23260
You can change any of the options of the smoothScroll
plugin after instantiation:
Setting options after initial call
If you need to change any of the options after you've already called
.smoothScroll()
, you can do so by passing the "options" string as the first argument and an options object as the second.
$el.smoothScroll('options', {
offset: newValue
});
Upvotes: 2