Comments (2)
JavaScript has a special keyword called arguments which provides access to an array-like object containing all arguments that were passed to a function. Importantly arguments contains all arguments passed to a function even if the function doesn’t declare any parameters. You can read more about it here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments
In the code you’ve referenced I’m doing a funky little bit of meta-programming which calls a function using the Function#apply method. The apply method takes two parameters, the scope to execute the function against and an array of arguments. I’m simply passing through whatever arguments were passed to function dynamically. You can read more about apply here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply
So the short of it is just call the methods on the $mixpanel service exactly as you would on the window.mixpanel object and all should just work as expected.
--
Dave Kuhn
AU: +61 410 817 855
US: +1 415 799 9234
http://au.linkedin.com/in/davidskuhn
On Mon, Nov 3, 2014 at 12:37 AM, mehtaad [email protected] wrote:
Hi,
I was trying to understand your below code
function callMixpanelFn(name) {
return function () {
var fn = window.mixpanel,
parts = name.split('.'),
scope, i;
for (i = 0; i < parts.length; i++) {
scope = fn;
fn = fn[parts[i]];
}
return fn.apply(scope, arguments);
}
I am not able to understand from were arguments parameter will get filled? you are not passing any parameters to function call except name.
Is their any chance to update a working demo code with a call to mixpanel api with arguments?
For example how would below function execute if I use your wrapper in my code?
mixpanel.track("signup", {
"age": 28,
"gender": "male",
"source": "facebook"
});
Thanks,Ashok
Reply to this email directly or view it on GitHub:
#1
from angular-mixpanel.
Thanks Dave. I will try it out.
From: Dave Kuhn <[email protected]>
To: kuhnza/angular-mixpanel [email protected]
Cc: mehtaad [email protected]
Sent: Monday, November 3, 2014 5:47 AM
Subject: Re: [angular-mixpanel] Understanding function callMixpanelFn(name) in your code (#1)
JavaScript has a special keyword called arguments which provides access to an array-like object containing all arguments that were passed to a function. Importantly arguments contains all arguments passed to a function even if the function doesn’t declare any parameters. You can read more about it here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments
In the code you’ve referenced I’m doing a funky little bit of meta-programming which calls a function using the Function#apply method. The apply method takes two parameters, the scope to execute the function against and an array of arguments. I’m simply passing through whatever arguments were passed to function dynamically. You can read more about apply here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply
So the short of it is just call the methods on the $mixpanel service exactly as you would on the window.mixpanel object and all should just work as expected.
--
Dave Kuhn
AU: +61 410 817 855
US: +1 415 799 9234
http://au.linkedin.com/in/davidskuhn
On Mon, Nov 3, 2014 at 12:37 AM, mehtaad [email protected] wrote:
Hi,
I was trying to understand your below code
function callMixpanelFn(name) {
return function () {
var fn = window.mixpanel,
parts = name.split('.'),
scope, i;
for (i = 0; i < parts.length; i++) {
scope = fn;
fn = fn[parts[i]];
}
return fn.apply(scope, arguments);
}
I am not able to understand from were arguments parameter will get filled? you are not passing any parameters to function call except name.
Is their any chance to update a working demo code with a call to mixpanel api with arguments?
For example how would below function execute if I use your wrapper in my code?
mixpanel.track("signup", {
"age": 28,
"gender": "male",
"source": "facebook"
});
Thanks,Ashok
Reply to this email directly or view it on GitHub:
https://github.com/kuhnza/angular-mixpanel/issues/1—
Reply to this email directly or view it on GitHub.
from angular-mixpanel.
Related Issues (16)
- Clear up confusion in readme.md about initializing mixpanel
- add mixpanel.people.union to api
- Expose cookies object? HOT 2
- $mixpanel.track - "Undefined is not a function" - Using minified version HOT 4
- Submit the module to npm registry HOT 4
- Some profiles not sent to MixPanel
- Mix panel error HOT 1
- Init question
- Are utm properties supported at this moment???
- angular-mixpanel doesnot work in Android App built with Ionic Cordova HOT 1
- Support mixpanel.reset HOT 1
- Support time_event
- Add your library to a cdn HOT 3
- How can i track page visit ? HOT 1
- Wrap init function HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from angular-mixpanel.