在自身内部访问无限功能的实例

时间:2016-05-28 10:11:05

标签: javascript solver ninjaframework

如何在自身内部获取匿名函数的实例?

function parent (val) {
    val.someProp = "abc"
    val()
}
parent(function(){
    return this.someProp; // how to access a someProp because this is window?
})

它必须是匿名的,它是一个回调,并且在传递给我的函数中,我将属性附加到回调并调用它。然后它应该返回自己的财产。

 public class Platformer2DUserControl : MonoBehaviour
{
    private PlatformerCharacter2D m_Character;
    private bool m_Jump;


    private void Awake()
    {
        m_Character = GetComponent<PlatformerCharacter2D>();
    }


    private void Update()
    {
        if (!m_Jump)
        {
            // Read the jump input in Update so button presses aren't missed.
            m_Jump = CrossPlatformInputManager.GetButtonDown("Jump");
        }
    }


    private void FixedUpdate()
    {
        // Read the inputs.
        bool crouch = Input.GetKey(KeyCode.LeftControl);
        float h = CrossPlatformInputManager.GetAxis("Horizontal");
        // Pass all parameters to the character control script.
        m_Character.Move(h, crouch, m_Jump);
        m_Jump = false;
    }
}

此外,我无法将道具传递给它。

1 个答案:

答案 0 :(得分:1)

我不确定这是一个很好的编程习惯,但你可以将自己作为一个参数发送给自己:

// If an empty value is still selected, don't go further to show the generate button
// and if the button was there, hide it.
if (unselected.length!==0) { $(".generate").hide(); return; };