Giter Site home page Giter Site logo

Comments (2)

kuhnza avatar kuhnza commented on June 11, 2024

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

@DaveKuhn

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.

mehtaad avatar mehtaad commented on June 11, 2024

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

@DaveKuhn

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.