Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8292021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:19:31+00:00 2026-06-08T13:19:31+00:00

I have the code snippet below: var ret_ = function(x){ return x; } var

  • 0

I have the code snippet below:

var ret_ = function(x){
    return x;
}
var make_cps=function(x,c_){
    return c_(x);
}
var pred = {
    _position: 0,
    setPosition: function (i) {
        _position = i
    },
    getPosition: function () {
        return _position
    },
    _size: 0,
    setSize: function (i) {
        _size = i
    },
    getSize: function () {
        return _size
    },
    _context: null,
    setContext: function (x) {
        _context = x
    },
    run: function () {
        return function (c_) {
            return make_cps(_position, c_);
        }(ret_) == 2;
    }
}    

When I run it like below, it runs correctly:

pred.setPosition(2)  
pred.setSize(10)  
pred.setContext(null)  
var res = pred.run()  
console.log(res)  // Output: true

but if I replace the _position to getPosition() an error occurs as getPosition() is not defined. Also if I change to this.getPosition() it says this doesn’t have a member called getPosition()

var pred = {
    _position: 0,
    setPosition: function (i) {
        _position = i
    },
    getPosition: function () {
        return _position
    },
    _size: 0,
    setSize: function (i) {
        _size = i
    },
    getSize: function () {
        return _size
    },
    _context: null,
    setContext: function (x) {
        _context = x
    },
    run: function () {
        return function (c_) {
            return make_cps(this.getPosition(), c_); // gives Error here
        }(ret_) == 2;
    }
}    

Please someone throw light on this issue.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T13:19:32+00:00Added an answer on June 8, 2026 at 1:19 pm

    You’ve lost your context. Where you’ve put this.getPosition(), this will return as the window object.

    If you alter the line to read

    return make_cps(pred.getPosition(), c_);
    

    It will work successfully.

    Alternately, you can change the run function to read

    run: function () {
      var that = this;
    
      return function (c_) {
          return make_cps(that.getPosition(), c_);
      }(ret_) == 2;
    }
    

    Edit: Clarification

    The reason that _position is still working rather than suffering from the same issue is that you’re not actually setting prev._position at all in your current code.

    setPosition: function (i) {
        _position = i
    },
    getPosition: function () {
        return _position
    }
    

    What it’s actually doing there is creating a new global variable called _position and using that instead.

    This code should actually read:

    setPosition: function (i) {
        this._position = i
    },
    getPosition: function () {
        return this._position
    },
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a javascript module name SceneModule, see the code snippet below var SceneModule
I have this code below: this.color = red; var o = {color: blue}; function
I have a code snippet as below <CheckBox Name=cb Margin=1,2,1,0 IsChecked={Binding Path=IsManager} IsEnabled=True/> Consider
I have below code snippet SimpleDateFormat dateFormat = new SimpleDateFormat( yyyy-MM-dd hh:mm:ss.SSS); String processedContentDate=2012-04-10
I have below snippet of code in which TestClass is extending jPanel which is
I have this snippet of code below. I want to pass the value of
Below is the snippet of my code. I have a JTable. I have extended
I have this code snippet: $(function() { $('.toolbar [id^=button]').on('click', function () { $(this) .css('background-color',
See my code snippet below: var list = ['one', 'two', 'three', 'four']; var str
In the code snippet below, I only have 1 element in the XML that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.